-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds an image generation CI and mvn build. The image is only built if tests are passed and on main branch. It is based on the fairly new Chainguard distroless project, which promises small, secure base images with SBOMS available for license compliance. To cleanly get there: dependencies were bumped maven wrapper was added dev instructions moved to sep standard file Signed-off-by: Josef Andersson <[email protected]>
- Loading branch information
1 parent
5748a25
commit 70b23f4
Showing
13 changed files
with
690 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Maven build | ||
|
||
on: [workflow_call] | ||
|
||
jobs: | ||
maven-matrix-build: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
java_version: [11] | ||
os: [windows-latest, macOS-latest, ubuntu-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK ${{ matrix.java_version }} | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: ${{ matrix.java_version }} | ||
distribution: "temurin" | ||
|
||
- name: Build jar | ||
if: contains(matrix.os, 'win') == false | ||
run: chmod +x ./mvnw | ||
- name: Maven Package | ||
run: ./mvnw --batch-mode --update-snapshots --file pom.xml package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
name: dcat-ap-processor workflow | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- v[0-9]+.[0-9]+.[0-9]+ | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
uses: ./.github/workflows/build.yml | ||
publish-container-image: | ||
needs: [test] | ||
if: github.ref == 'refs/heads/main' | ||
uses: ./.github/workflows/publish-container-image.yml |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: Publish Container image | ||
|
||
on: [workflow_call] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: dcat-ap-processor | ||
|
||
jobs: | ||
|
||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
|
||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
|
||
- name: Inspect builder | ||
run: | | ||
echo "Platforms: ${{ steps.buildx.outputs.platforms }}" | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for distribution image | ||
id: metadist | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} | ||
flavor: | | ||
latest=true | ||
tags: | | ||
type=raw,value={{branch}},priority=1,enable=${{ !startsWith(github.ref, 'refs/tags/v') }} | ||
type=semver,pattern={{version}},priority=2 | ||
type=raw,value=${{ env.IMAGE_NAME }}-{{branch}}-{{date 'YYYYMMDD'}}-{{sha}},priority=31,enable=${{ !startsWith(github.ref, 'refs/tags/v') }} | ||
type=raw,value=${{ env.IMAGE_NAME }}-{{tag}}-{{date 'YYYYMMDD'}}-{{sha}},priority=32, enable=${{ startsWith(github.ref, 'refs/tags/v') }} | ||
- name: Build and push distribution image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: Dockerfile | ||
platforms: linux/amd64 | ||
push: true | ||
tags: ${{ steps.metadist.outputs.tags }} | ||
labels: ${{ steps.metadist.outputs.labels }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Arbetssätt vid lokal utveckling | ||
|
||
## Använda Docker | ||
Kopiera fil från lokal dator till den container man vill köra från | ||
|
||
[docker cp](https://docs.docker.com/engine/reference/commandline/cp/) | ||
``` | ||
$ docker cp apidef.raml pensive_gates:\opt\apidef.raml | ||
``` | ||
|
||
Använda docker på dator. Bygg docker image | ||
``` | ||
$ mvn clean install | ||
$ docker build --no-cache -t "dcatprocessor" . | ||
``` | ||
Starta containern | ||
Från Docker Desktop genom att gå till images och klicka Run samt sätta "Ports/Local port" till 8080 | ||
eller från kommandorad | ||
``` | ||
$ docker run -p 8080:8080 -d --name dcatprocessor dcatprocessor | ||
``` | ||
Kopiera testfiler till container:/apidef<br> | ||
I en riktig miljö hade api producenterna kopierat sina apidefinitioner till en gemensam katalog | ||
och satt sin RDF pipeline att läsa upp dem därifrån.<br> | ||
(docker cp source containername:destination) | ||
``` | ||
(docker cp source containername:destination) | ||
$ docker cp apidef.raml hopeful_boyd:/apidef | ||
``` | ||
|
||
## Köra direkt från jar-filen | ||
För att köra verktyget direkt från jarfilen öppnar man ett kommandfönster och går till där jar-filen ligger. Sedan kör du: | ||
``` | ||
java -jar <jar-file-name>.jar | ||
``` | ||
Detta kör igång verktyget lokalt på datorn. | ||
|
||
# Göra anrop till Verktyget | ||
Kör anrop till rest api via git bash, Postman eller annat verktyg<br> | ||
|
||
``` | ||
Läser filer från /apidef på containern | ||
$ curl http://localhost:8080/api/v1/rdf | ||
``` | ||
eller testa med anrop via formulär metoden (Stå i samma katalog som en fil som heter obl_rek_raml.raml eller peka ut nån annan) | ||
``` | ||
$ curl -F apispecification= -F create=create -F apitype=apitype.R10 -F apifile=@obl_rek_raml.raml http://localhost:8080/generate/dcat/0 | ||
``` | ||
Verktyget har även ett enklare GUI man kan använda för att skicka in apispecifikationer genom. GUI:t startas i webläsare genom att gå till (förutsatt att verktyget körs på localhost): | ||
|
||
http://localhost:8080/ | ||
|
||
# Loggning | ||
Exceptions skrivs till container loggen "/opt/logs/dcatprocessor.log".<br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,28 @@ | ||
FROM docker.io/adoptopenjdk/openjdk11:jdk-11.0.2.9-slim AS build | ||
|
||
RUN apt-get -y clean && apt-get -y update && apt-get -y install maven | ||
|
||
RUN mkdir /build | ||
COPY pom.xml /build/ | ||
COPY src /build/src/ | ||
COPY .mvn /build/.mvn | ||
COPY mvnw /build/mvnw | ||
WORKDIR /build | ||
RUN mvn clean package spring-boot:repackage | ||
RUN ./mvnw clean package spring-boot:repackage | ||
|
||
|
||
|
||
FROM docker.io/adoptopenjdk/openjdk11:jre-11.0.11_9-debianslim | ||
# Note: The default non root chainguard user is 65532 | ||
FROM cgr.dev/chainguard/jdk:openjdk-jre-11-20221109 | ||
|
||
COPY --from=build /build/target/dcat-ap-processor-0.0.1-SNAPSHOT.jar /opt/app.jar | ||
USER root | ||
RUN mkdir -p /opt/.logs \ | ||
&& mkdir -p /apidef | ||
RUN chown -R 65532:65532 /opt/ | ||
USER 65532 | ||
COPY --from=build /build/target/dcat-ap-processor-0.0.2-SNAPSHOT.jar /opt/app.jar | ||
|
||
RUN apt-get -y clean \ | ||
&& apt-get -y update \ | ||
&& apt-get -y install --no-install-recommends locales \ | ||
&& apt-get -y autoremove --purge \ | ||
&& apt-get -y clean \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& mkdir -p /apidef \ | ||
&& sed -i -e 's/# sv_SE.UTF-8 UTF-8/sv_SE.UTF-8 UTF-8/' /etc/locale.gen \ | ||
&& locale-gen | ||
|
||
ENV JDK_JAVA_OPTIONS -Duser.language=sv-SE -Duser.region=SE -Duser.timezone=Europe/Stockholm | ||
WORKDIR /opt | ||
ENV PORT 8080 | ||
EXPOSE 8080 | ||
ENTRYPOINT exec java $JAVA_OPTS -jar app.jar | ||
|
||
## Set the locale | ||
ENV LANG sv_SE.UTF-8 | ||
ENV LANGUAGE sv_SE:sv | ||
ENV LC_ALL sv_SE.UTF-8 | ||
CMD ["-jar","app.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.