aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Hoerr <kjhoerr@protonmail.com>2023-01-09 14:43:31 -0500
committerKevin J Hoerr <kjhoerr@protonmail.com>2025-08-18 11:51:28 -0400
commit8b6bf5ac9e7c80d84771c8158fe670b44c4afa15 (patch)
treeeea1985668b17d78b141087e11c90366932ef8d4
parent4bafa6f596ffbb8053fbb9feb700932f4ca14bea (diff)
downloadpantry-8b6bf5ac9e7c80d84771c8158fe670b44c4afa15.tar.gz
pantry-8b6bf5ac9e7c80d84771c8158fe670b44c4afa15.tar.bz2
pantry-8b6bf5ac9e7c80d84771c8158fe670b44c4afa15.zip
Add multistage docker file for ease of use (#41)
-rw-r--r--.dockerignore14
-rw-r--r--.github/workflows/build.yml14
-rw-r--r--src/main/docker/Dockerfile.multistage48
3 files changed, 68 insertions, 8 deletions
diff --git a/.dockerignore b/.dockerignore
index 94810d0..5ea3dee 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,5 +1,9 @@
-*
-!target/*-runner
-!target/*-runner.jar
-!target/lib/*
-!target/quarkus-app/* \ No newline at end of file
+.devcontainer
+.git
+.gitattributes
+.github
+.vscode
+out
+node_modules
+.env*
+src/main/docker
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index bc2337e..82188ba 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -12,26 +12,35 @@ jobs:
runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ image-type: [ native, multistage ]
+
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18.x
+ if: matrix.image-type == 'native'
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'yarn'
- name: Install Node.js packages
+ if: matrix.image-type == 'native'
run: yarn install
- name: Run build injection
+ if: matrix.image-type == 'native'
run: yarn inject
- name: Use Java 17
+ if: matrix.image-type == 'native'
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
- name: Maven package
+ if: matrix.image-type == 'native'
run: mvn package -Pnative -Dquarkus.native.container-build=true -Dquarkus.container-image.build=true
- name: Setup Docker buildx
@@ -52,9 +61,8 @@ jobs:
with:
context: .
push: true
- file: src/main/docker/Dockerfile.native
- tags: ${{ steps.meta.outputs.tags }}
+ file: src/main/docker/Dockerfile.${{ matrix.image-type }}
+ tags: ${{ env.IMAGE_NAME }}:${{ matrix.image-type }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
-
diff --git a/src/main/docker/Dockerfile.multistage b/src/main/docker/Dockerfile.multistage
new file mode 100644
index 0000000..a521a09
--- /dev/null
+++ b/src/main/docker/Dockerfile.multistage
@@ -0,0 +1,48 @@
+## Stage 1: install yarn dependencies from cache
+FROM node:current AS base-yarn
+WORKDIR /app
+COPY package*.json ./
+COPY yarn.lock ./
+COPY .yarnrc.yml ./
+COPY .yarn ./.yarn
+RUN yarn install --immutable --immutable-cache
+
+## Stage 2 : build with yarn
+FROM base-yarn AS build-yarn
+WORKDIR /app
+COPY --from=base-yarn /app/package.json ./
+COPY --from=base-yarn /app/yarn.lock ./
+COPY --from=base-yarn /app/.yarnrc.yml ./
+COPY --from=base-yarn /app/.yarn/cache ./.yarn/cache
+COPY --from=base-yarn /app/.yarn/plugins ./.yarn/plugins
+COPY --from=base-yarn /app/.yarn/releases ./.yarn/releases
+RUN yarn install
+COPY next-env.d.ts /app
+COPY next.config.js /app
+COPY postcss.config.js /app
+COPY tailwind.config.js /app
+COPY tsconfig.json /app
+COPY src /app/src
+## outputs to /app/out
+RUN yarn build
+
+## Stage 3 : build with maven builder image with native capabilities
+FROM quay.io/quarkus/ubi-quarkus-graalvmce-builder-image:22.3-java17 AS build-quarkus
+USER root
+RUN microdnf -y install --nodocs maven
+COPY --chown=quarkus:quarkus pom.xml /code/
+USER quarkus
+WORKDIR /code
+RUN mvn -B org.apache.maven.plugins:maven-dependency-plugin:3.1.2:go-offline
+COPY --from=build-yarn /app/out /code/src/main/resources/META-INF/resources
+COPY src /code/src
+RUN mvn -Pnative clean package
+
+## Stage 4 : create the docker final image
+FROM quay.io/quarkus/quarkus-distroless-image:2.0 AS release
+COPY --from=build-quarkus /code/target/*-runner /application
+
+EXPOSE 8080
+USER nonroot
+
+CMD ["./application", "-XX:+PrintGC", "-XX:+PrintGCTimeStamps", "-XX:+VerboseGC", "+XX:+PrintHeapShape", "-Xmx128m", "-Dquarkus.http.host=0.0.0.0"]