Skip to content

Commit

Permalink
Merge pull request #33 from naviqore/feature/NAV-72-docker
Browse files Browse the repository at this point in the history
Feature/nav 72 docker
  • Loading branch information
munterfi authored May 30, 2024
2 parents 5c6da3d + 8fff739 commit 979a543
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 21 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Docker CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build image
run: |
COMMIT_HASH=$(git rev-parse --short HEAD)
IMAGE_TAG=ghcr.io/${{ github.repository }}:${COMMIT_HASH}
docker build . --file Dockerfile --tag $IMAGE_TAG
30 changes: 30 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Docker publish

on:
push:
branches: [ "main" ]
tags:
- 'v[0-9]+\.[0-9]+\.[0-9]+(-.*)?'

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
- name: Set up environment variables
run: echo "IMAGE_TAG=ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${{ github.event.release.tag_name }}" >> $GITHUB_ENV

- name: Login to ghcr
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Build image
run: |
docker build . --file Dockerfile --tag $IMAGE_TAG
- name: Push image to ghcr
run: |
docker push $IMAGE_TAG
29 changes: 9 additions & 20 deletions .github/workflows/maven-ci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven
name: Maven CI

on:
push:
Expand All @@ -16,20 +8,17 @@ on:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
- uses: actions/checkout@v4
- name: Setup
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B verify --file pom.xml
java-version: '21'
cache: 'maven'

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
# - name: Update dependency graph
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
- name: Build
# use verify instead of package to include integration tests
run: mvn -B verify --file pom.xml
33 changes: 33 additions & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Maven publish

on:
push:
branches: [ "main" ]
tags:
- 'v[0-9]+\.[0-9]+\.[0-9]+(-.*)?'

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
- name: Setup
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Build
run: mvn -B package --file pom.xml

- name: Publish
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM openjdk:21-jdk-slim AS build
WORKDIR /app
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
RUN ./mvnw dependency:go-offline -B
COPY src ./src
RUN ./mvnw clean package -DskipTests

FROM openjdk:21-jdk-slim
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>ch.naviqore</groupId>
<artifactId>public-transit-service</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>0.1.0</version>

<name>Public Transit Service</name>
<description>
Expand Down Expand Up @@ -47,6 +47,14 @@
<url>https://github.com/naviqore/public-transit-service</url>
</scm>

<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/naviqore/public-transit-service</url>
</repository>
</distributionManagement>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>21</java.version>
Expand Down

0 comments on commit 979a543

Please sign in to comment.