Skip to content

Commit 569a06d

Browse files
Merge pull request #36 from kit-data-manager/development
Add packaging
2 parents 947d2e8 + 7fb44eb commit 569a06d

File tree

15 files changed

+711
-20
lines changed

15 files changed

+711
-20
lines changed

.github/workflows/docker-publish.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Create and publish a Docker image on github
2+
name: Create and publish a Docker image
3+
4+
# Configures this workflow to run every time a change
5+
# is pushed to the 'main' branch.
6+
on:
7+
push:
8+
# Publish `main` as Docker `latest` image.
9+
branches:
10+
- main
11+
12+
# Publish `v1.2.3` tags as releases.
13+
tags:
14+
- v*
15+
- '*-v*'
16+
17+
# Defines two custom environment variables for the workflow.
18+
# These are used for the Container registry domain, and a
19+
# name for the Docker image that this workflow builds.
20+
env:
21+
REGISTRY: ghcr.io
22+
IMAGE_NAME: ${{ github.repository }}
23+
24+
# Two jobs for creating and pushing Docker image
25+
# - build-and-push-image -> triggered by commits on main and tagging with semantic version (e.g.: v1.2.3)
26+
# - build-and-push-image-of-branch -> triggered by tags matching '*-v*' (e.g.: Version_1-v1.2.3)
27+
jobs:
28+
build-and-push-image:
29+
runs-on: ubuntu-latest
30+
if: ${{ contains(github.ref_name, '-') == failure() }}
31+
# Sets the permissions granted to the `GITHUB_TOKEN`
32+
# for the actions in this job.
33+
permissions:
34+
contents: read
35+
packages: write
36+
#
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v4
40+
# Uses the `docker/login-action` action to log in to the Container
41+
# registry using the account and password that will publish the packages.
42+
# Once published, the packages are scoped to the account defined here.
43+
- name: Log in to the Container registry
44+
uses: docker/login-action@v3
45+
with:
46+
registry: ${{ env.REGISTRY }}
47+
username: ${{ github.actor }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
49+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about)
50+
# to extract tags and labels that will be applied to the specified image.
51+
# The `id` "meta" allows the output of this step to be referenced in a
52+
# subsequent step. The `images` value provides the base name for the tags
53+
# and labels.
54+
- name: Extract metadata (tags, labels) for Docker
55+
id: meta
56+
uses: docker/metadata-action@v5
57+
with:
58+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
59+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
60+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
61+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
62+
- name: Build and push Docker image
63+
uses: docker/build-push-action@v5
64+
with:
65+
context: .
66+
push: true
67+
tags: ${{ steps.meta.outputs.tags }}
68+
labels: ${{ steps.meta.outputs.labels }}
69+
build-and-push-image-of-branch:
70+
runs-on: ubuntu-latest
71+
if: contains(github.ref_name, '-')
72+
# Sets the permissions granted to the `GITHUB_TOKEN`
73+
# for the actions in this job.
74+
permissions:
75+
contents: read
76+
packages: write
77+
#
78+
steps:
79+
- name: Split first part
80+
env:
81+
TAG: ${{ github.ref_name }}
82+
id: split
83+
run: echo "branch=${TAG%-v*}" >> $GITHUB_OUTPUT
84+
- name: Test variable
85+
run: |
86+
echo ${{ steps.split.outputs.branch }}
87+
- name: Checkout repository
88+
uses: actions/checkout@v4
89+
# Uses the `docker/login-action` action to log in to the Container
90+
# registry using the account and password that will publish the packages.
91+
# Once published, the packages are scoped to the account defined here.
92+
- name: Log in to the Container registry
93+
uses: docker/login-action@v3
94+
with:
95+
registry: ${{ env.REGISTRY }}
96+
username: ${{ github.actor }}
97+
password: ${{ secrets.GITHUB_TOKEN }}
98+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about)
99+
# to extract tags and labels that will be applied to the specified image.
100+
# The `id` "meta" allows the output of this step to be referenced in a
101+
# subsequent step. The `images` value provides the base name for the tags
102+
# and labels.
103+
- name: Extract metadata (tags, labels) for Docker
104+
id: meta-branch
105+
uses: docker/metadata-action@v5
106+
with:
107+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{steps.split.outputs.branch}}
108+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
109+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
110+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
111+
- name: Build and push Docker image
112+
uses: docker/build-push-action@v5
113+
with:
114+
context: .
115+
push: true
116+
tags: ${{ steps.meta-branch.outputs.tags }}
117+
labels: ${{ steps.meta-branch.outputs.labels }}
118+

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- Improved file extension correction for download allowing to distinguish between different textfile flavours
810

911
## [1.0.2] - date 2023-07-27
1012
### New Features

Dockerfile

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
####################################################
2+
# START GLOBAL DECLARATION
3+
####################################################
4+
ARG REPO_NAME_DEFAULT=mapping-service
5+
ARG REPO_PORT_DEFAULT=8095
6+
ARG SERVICE_ROOT_DIRECTORY_DEFAULT=/spring/
7+
####################################################
8+
# END GLOBAL DECLARATION
9+
####################################################
10+
11+
####################################################
12+
# Building environment (java & git)
13+
####################################################
14+
FROM eclipse-temurin:17 AS build-env-java
15+
LABEL maintainer=webmaster@datamanager.kit.edu
16+
LABEL stage=build-env
17+
18+
# Install git, python3, pip and bash as additional requirement
19+
RUN apt-get -y update && \
20+
apt-get -y upgrade && \
21+
apt-get install -y --no-install-recommends git bash python3 python3-pip && \
22+
apt-get clean \
23+
&& rm -rf /var/lib/apt/lists/*
24+
25+
####################################################
26+
# Building service
27+
####################################################
28+
FROM build-env-java AS build-service-mapping-service
29+
LABEL maintainer=webmaster@datamanager.kit.edu
30+
LABEL stage=build-contains-sources
31+
32+
# Fetch arguments from above
33+
ARG REPO_NAME_DEFAULT
34+
ARG SERVICE_ROOT_DIRECTORY_DEFAULT
35+
36+
# Declare environment variables
37+
ENV REPO_NAME=${REPO_NAME_DEFAULT}
38+
ENV SERVICE_DIRECTORY=$SERVICE_ROOT_DIRECTORY_DEFAULT$REPO_NAME
39+
40+
# Create directory for repo
41+
RUN mkdir -p /git/${REPO_NAME}
42+
WORKDIR /git/${REPO_NAME}
43+
COPY . .
44+
RUN cp settings/application-docker.properties settings/application-default.properties
45+
# Build service in given directory
46+
RUN bash ./build.sh $SERVICE_DIRECTORY
47+
48+
####################################################
49+
# Runtime environment 4 metastore2
50+
####################################################
51+
FROM eclipse-temurin:17 AS run-service-mapping-service
52+
LABEL maintainer=webmaster@datamanager.kit.edu
53+
LABEL stage=run
54+
55+
# Fetch arguments from above
56+
ARG REPO_NAME_DEFAULT
57+
ARG REPO_PORT_DEFAULT
58+
ARG SERVICE_ROOT_DIRECTORY_DEFAULT
59+
60+
# Declare environment variables
61+
ENV REPO_NAME=${REPO_NAME_DEFAULT}
62+
ENV SERVICE_DIRECTORY=${SERVICE_ROOT_DIRECTORY_DEFAULT}${REPO_NAME}
63+
ENV REPO_PORT=${REPO_PORT_DEFAULT}
64+
65+
# Install python3, pip and bash as additional requirement
66+
RUN apt-get -y update && \
67+
apt-get -y upgrade && \
68+
apt-get install -y --no-install-recommends python3 python3-pip bash && \
69+
apt-get clean \
70+
&& rm -rf /var/lib/apt/lists/*
71+
72+
# Copy service from build container
73+
RUN mkdir -p ${SERVICE_DIRECTORY}
74+
WORKDIR ${SERVICE_DIRECTORY}
75+
COPY --from=build-service-mapping-service ${SERVICE_DIRECTORY} ./
76+
77+
# Define repo port
78+
EXPOSE ${REPO_PORT}
79+
ENTRYPOINT ["bash", "./run.sh"]

README.md

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Dependencies that are needed to build and are not being downloaded via gradle:
2020
- Python 3
2121
- pip (runtime only)
2222

23-
`./gradlew -Pclean-release build`
23+
`./gradlew build`
2424

2525
### Python Location
2626

@@ -30,7 +30,7 @@ the mapping-service on a machine on which the Python installation is located els
3030
used at compile time externally, i.e.:
3131

3232
```
33-
.\gradlew -Pclean-release "-DpythonExecutable=file:///C:/Python310/python.exe" build
33+
.\gradlew "-DpythonExecutable=file:///C:/Python310/python.exe" build
3434
```
3535

3636
## How to start
@@ -74,6 +74,139 @@ and `spring.datasource.url`) in a separate folder from where you then call the m
7474

7575
`java -jar mapping-service-<VERSION>.jar`
7676

77+
## Installation
78+
There are three ways to install metaStore2 as a microservice:
79+
- [Using](#Installation-via-GitHub-Packages) the image available via [GitHub Packages](https://github.com/orgs/kit-data-manager/packages?repo_name=mapping-service) (***recommended***)
80+
- [Building](#Build-docker-container-locally) docker image locally
81+
- [Building](#Build-and-run-locally) and running locally
82+
83+
## Installation via GitHub Packages
84+
### Prerequisites
85+
In order to run this microservice via docker you'll need:
86+
87+
* [Docker](https://www.docker.com/)
88+
89+
### Installation
90+
Typically, there is no need for locally building images as all version are accessible via GitHub Packages.
91+
Have a look of available images and their tags [here](https://github.com/orgs/kit-data-manager/packages?repo_name=mapping-service)
92+
Just follow instructions [below](#Build-docker-container).
93+
94+
## Build docker container locally
95+
### Prerequisites
96+
In order to run this microservice via docker you'll need:
97+
98+
* [Docker](https://www.docker.com/)
99+
* [git](https://git-scm.com/)
100+
101+
### Installation
102+
#### Clone repository
103+
First of all you'll have to clone this repository:
104+
```
105+
user@localhost:/home/user/$ git clone https://github.com/kit-data-manager/mapping-service.git
106+
Clone to 'mapping-service'
107+
[...]
108+
user@localhost:/home/user/$ cd mapping-service
109+
user@localhost:/home/user/mapping-service$
110+
```
111+
112+
#### Create image
113+
Now you'll have to create an image containing the microservice. This can be done via a script.
114+
On default the created images will be tagged as follows:
115+
116+
*'latest tag'-'actual date(yyyy-mm-dd)'* (e.g.: 1.2.0-2023-06-27)
117+
118+
```
119+
user@localhost:/home/user/mapping-service$ bash docker/buildDocker.sh
120+
---------------------------------------------------------------------------
121+
Build docker container ghcr.io/kit-data-manager/mapping-service:1.2.0-2023-06-27
122+
---------------------------------------------------------------------------
123+
[...]
124+
---------------------------------------------------------------------------
125+
Now you can create and start the container by calling ...
126+
---------------------------------------------------------------------------
127+
user@localhost:/home/user/mapping-service$
128+
```
129+
130+
#### Build docker container
131+
After building image you have to create (and start) a container for executing microservice:
132+
```
133+
# If you want to use a specific image you may list all possible tags first.
134+
user@localhost:/home/user/mapping-service$ docker images ghcr.io/kit-data-manager/mapping-service --format {{.Tag}}
135+
1.2.0-2023-06-27
136+
user@localhost:/home/user/mapping-service$ docker run -d -p8095:8095 --name mapping4docker ghcr.io/kit-data-manager/mapping-service:1.2.0-2023-06-27
137+
57c973e7092bfc3778569f90632d60775dfecd12352f13a4fd2fdf4270865286
138+
user@localhost:/home/user/mapping-service$
139+
```
140+
141+
#### Customize settings
142+
If you want to overwrite default configuration of your docker container you have to
143+
'mount' a config directory containing 'application.properties' with your adapted settings.
144+
Therefor you have to provide an additional flag to the command mentioned before:
145+
```
146+
# Overwriting default settings
147+
# Create config folder
148+
user@localhost:/home/user/mapping-service$ mkdir config
149+
# Place your own 'application.properties' inside the config directory
150+
# Create/run container
151+
user@localhost:/home/user/mapping-service$ docker run -d -p8095:8095 -v `pwd`/config:/spring/mapping-service/config --name mapping4docker ghcr.io/kit-data-manager/mapping-service:1.2.0-2023-06-27
152+
57c973e7092bfc3778569f90632d60775dfecd12352f13a4fd2fdf4270865286
153+
user@localhost:/home/user/mapping-service$
154+
```
155+
156+
#### Stop docker container
157+
If you want to stop container just type
158+
```
159+
user@localhost:/home/user/mapping-service$ docker stop mapping4docker
160+
```
161+
162+
#### (Re)start docker container
163+
If you want to (re)start container just type
164+
```
165+
user@localhost:/home/user/mapping-service$ docker start mapping4docker
166+
```
167+
168+
## Build and run locally
169+
### Prerequisites
170+
In order to run this microservice via docker you'll need:
171+
172+
* [Java SE Development Kit >= 17](https://openjdk.java.net/)
173+
* [git](https://git-scm.com/)
174+
175+
### Installation
176+
#### Clone repository
177+
First of all you'll have to clone this repository:
178+
```
179+
user@localhost:/home/user/$ git clone https://github.com/kit-data-manager/mapping-service.git
180+
Clone to 'mapping-service'
181+
[...]
182+
user@localhost:/home/user/$ cd mapping-service
183+
user@localhost:/home/user/mapping-service$
184+
```
185+
#### Build service
186+
To build service just execute the build.sh script:
187+
```
188+
user@localhost:/home/user/mapping-service$bash build.sh /PATH/TO/EMPTY/INSTALLATION/DIRECTORY
189+
---------------------------------------------------------------------------
190+
Build microservice of mapping-service at /PATH/TO/EMPTY/INSTALLATION/DIRECTORY
191+
---------------------------------------------------------------------------
192+
[...]
193+
---------------------------------------------------------------------------
194+
Now you can start the service by calling /PATH/TO/EMPTY/INSTALLATION/DIRECTORY/run.sh
195+
---------------------------------------------------------------------------
196+
user@localhost:/home/user/mapping-service$
197+
```
198+
#### Customize settings
199+
If you want to overwrite default configuration of your docker container you have to
200+
add a file named 'application.properties' to the 'config' directory inside your installation
201+
path (/PATH/TO/EMPTY/INSTALLATION/DIRECTORY)selected before. The added file should
202+
only contain your adapted settings. e.g. in case you want to change only the port to '1234' your
203+
'application.properties' should look like this:
204+
```
205+
# Overwriting default settings from ../application.properties
206+
# Server settings
207+
server.port: 1234
208+
```
209+
77210
## License
78211

79212
See [LICENSE file in this repository](LICENSE).

build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ jar {
128128
archiveBaseName = 'mapping-service'
129129
// version is defined in file 'gradle.properties'
130130
archiveVersion = System.getenv('version')
131+
// disable plain jar file
132+
enabled = false
131133
}
132134

133135
springBoot {
@@ -157,3 +159,11 @@ task buildPluginJar(type: Jar) {
157159
from sourceSets.main.output
158160
include '**/plugins/impl/*.class'
159161
}
162+
163+
// task for printing project name.
164+
// should be the last task inside file
165+
task printProjectName {
166+
doLast {
167+
println "${project.name}"
168+
}
169+
}

0 commit comments

Comments
 (0)