-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from saneci/feature/docker
Closes #43
- Loading branch information
Showing
7 changed files
with
139 additions
and
5 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,29 @@ | ||
name: Continuous Delivery | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
needs: [integration-tests] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repository to the runner | ||
uses: actions/checkout@v4 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
db_username: ${{ secrets.DB_USERNAME }} | ||
db_password: ${{ secrets.DB_PASSWORD }} | ||
context: . | ||
push: true | ||
target: final | ||
tags: ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:latest |
5 changes: 3 additions & 2 deletions
5
.github/workflows/integration-tests.yml → .github/workflows/integration.yml
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
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,2 +1,18 @@ | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip | ||
# 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 | ||
# | ||
# http://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.6.3/apache-maven-3.6.3-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.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,55 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
# Create a base stage. | ||
FROM eclipse-temurin:17-jdk-jammy AS base | ||
WORKDIR /build | ||
COPY --chmod=0755 mvnw mvnw | ||
COPY .mvn/ .mvn/ | ||
|
||
# Create a stage for resolving and downloading dependencies. | ||
FROM base AS deps | ||
WORKDIR /build | ||
RUN --mount=type=bind,source=pom.xml,target=pom.xml \ | ||
--mount=type=cache,target=/root/.m2 \ | ||
./mvnw dependency:go-offline -DskipTests | ||
|
||
# Create a stage for testing. | ||
FROM base AS test | ||
WORKDIR /build | ||
COPY ./src src/ | ||
RUN --mount=type=bind,source=pom.xml,target=pom.xml \ | ||
--mount=type=cache,target=/root/.m2 \ | ||
./mvnw test | ||
|
||
# Create a stage for building the application based on the stage with downloaded dependencies. | ||
FROM deps AS package | ||
WORKDIR /build | ||
COPY ./src src/ | ||
RUN --mount=type=bind,source=pom.xml,target=pom.xml \ | ||
--mount=type=cache,target=/root/.m2 \ | ||
./mvnw package -DskipTests && \ | ||
mv target/$(./mvnw help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout).jar target/app.jar | ||
|
||
# Create a stage for extracting the application into separate layers. | ||
FROM package AS extract | ||
WORKDIR /build | ||
RUN java -Djarmode=layertools -jar target/app.jar extract --destination target/extracted | ||
|
||
# Create a new stage for running the application that contains the minimal runtime dependencies for the application. | ||
FROM eclipse-temurin:17-jre-jammy AS final | ||
ARG UID=10001 | ||
RUN adduser \ | ||
--disabled-password \ | ||
--gecos "" \ | ||
--home "/nonexistent" \ | ||
--shell "/sbin/nologin" \ | ||
--no-create-home \ | ||
--uid "${UID}" \ | ||
appuser | ||
USER appuser | ||
COPY --from=extract build/target/extracted/dependencies/ ./ | ||
COPY --from=extract build/target/extracted/spring-boot-loader/ ./ | ||
COPY --from=extract build/target/extracted/snapshot-dependencies/ ./ | ||
COPY --from=extract build/target/extracted/application/ ./ | ||
EXPOSE 8080 | ||
ENTRYPOINT [ "java", "org.springframework.boot.loader.launch.JarLauncher" ] |
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,33 @@ | ||
services: | ||
server: | ||
build: | ||
context: . | ||
ports: | ||
- 8080:8080 | ||
depends_on: | ||
postgres: | ||
condition: service_healthy | ||
environment: | ||
- DATASOURCE_URL=jdbc:postgresql://postgres:5432/book_library | ||
- DATASOURCE_USERNAME=${DB_USERNAME} | ||
- DATASOURCE_PASSWORD=${DB_PASSWORD} | ||
- DAYS_UNTIL_BOOK_OVERDUE=10 | ||
postgres: | ||
image: postgres:16 | ||
restart: always | ||
volumes: | ||
- postgres-data:/var/lib/postgresql/data | ||
environment: | ||
- POSTGRES_DB=book_library | ||
- POSTGRES_USER=${DB_USERNAME} | ||
- POSTGRES_PASSWORD=${DB_PASSWORD} | ||
ports: | ||
- 5432:5432 | ||
healthcheck: | ||
test: [ "CMD", "pg_isready", "-U", "${DB_USERNAME}" ] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
|
||
volumes: | ||
postgres-data: |
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
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