Skip to content

Commit

Permalink
feat : change Dockerfile and add build.yaml (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoBouttes authored Apr 30, 2024
1 parent 29852e3 commit 82a32e3
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 110 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Build release candidate

on:
release:
types: [created]
branches:
- main

jobs:
check-version:
runs-on: ubuntu-latest
outputs:
release-version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get version
id: version
run: echo "version=$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)-SNAPSHOT" >> $GITHUB_OUTPUT

- name: Print version
run: echo ${{ steps.version.outputs.version }}

- uses: mukunku/[email protected]
name: Check tag existence
id: check-tag-exists
with:
tag: ${{ steps.version.outputs.version }}

- name: Tag verification
id: check-tag
run: |
if [[ "${{ steps.check-tag-exists.outputs.exists }}" == "true" ]]; then
echo "Nothing to tag/release, the tag ${{ steps.version.outputs.version }} already exists"
exit 1
fi
build-release:
runs-on: ubuntu-latest
steps:
- name: Extract branch name
shell: bash
run: echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >>$GITHUB_OUTPUT
id: extract_branch

- uses: actions/checkout@v4
with:
ref: ${{ steps.extract_branch.outputs.branch }}

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "17"

- name: Build API
run: mvn package -Dchangelist=-SNAPSHOT --no-transfer-progress

- name: Upload API jar
uses: actions/upload-artifact@v4
with:
name: app-jar
path: target/*.jar

docker:
needs:
- check-version
- build-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Download uploaded jar
uses: actions/download-artifact@v4
with:
name: app-jar
path: target/

- name: Publish to Docker Hub
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: inseefr/metadata-api
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
tags: "latest, ${{ needs.check-version.outputs.release-version }}"
105 changes: 0 additions & 105 deletions .github/workflows/ci.yml

This file was deleted.

13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
FROM tomcat
FROM eclipse-temurin:21-jre-alpine
WORKDIR /application

ADD target/*.war /usr/local/tomcat/webapps/
RUN addgroup -g 10000 javagroup
RUN adduser -D -s / -u 10000 javauser -G javagroup
RUN chown -R 10000:10000 /application

EXPOSE 8080

CMD ["catalina.sh", "run"]
USER 10000
COPY target/*.jar metadata-api.jar
ENTRYPOINT ["java", "-jar", "/application/metadata-api.jar"]

0 comments on commit 82a32e3

Please sign in to comment.