From 7ee2687300b7bc2d1b27d3f6ef2c1caee7bec164 Mon Sep 17 00:00:00 2001 From: Mo Kweon Date: Sun, 12 Sep 2021 20:37:01 -0700 Subject: [PATCH] fix: Dockerfile --- .github/workflows/release.yaml | 95 ++++++++++++++++++++++++++++++++++ .releaserc | 10 ++++ Dockerfile | 6 ++- 3 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yaml create mode 100644 .releaserc diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..77fd178 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,95 @@ +name: Release + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: "11" + distribution: "adopt" + - run: gradle build + - run: gradle test + + release: + runs-on: ubuntu-latest + needs: + - build + outputs: + # Whether a new release was published (true or false) + new_release_published: ${{ steps.semantic.outputs.new_release_published }} + # Version of the new release. (e.g. 1.3.0) + new_release_version: ${{ steps.semantic.outputs.new_release_version }} + # Major version of the new release. (e.g. 1) + new_release_major_version: ${{ steps.semantic.outputs.new_release_major_version }} + # Minor version of the new release. (e.g. 3) + new_release_minor_version: ${{ steps.semantic.outputs.new_release_minor_version }} + # Patch version of the new release. (e.g. 0) + new_release_patch_version: ${{ steps.semantic.outputs.new_release_patch_version }} + # The distribution channel on which the last release was initially made available (undefined for the default distribution channel). + new_release_channel: ${{ steps.semantic.outputs.new_release_channel }} + # The release notes for the new release. + new_release_notes: ${{ steps.semantic.outputs.new_release_notes }} + + steps: + - uses: actions/checkout@v2 + - uses: cycjimmy/semantic-release-action@v2 + id: semantic + with: + semantic_version: 17 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + docker: + runs-on: ubuntu-latest + + needs: + - release + + if: ${{ needs.release.outputs.new_release_published == 'true' }} + + steps: + - uses: actions/checkout@v2 + - name: Docker meta + id: docker_meta + uses: docker/metadata-action@v3 + with: + images: ghcr.io/codingpot/pr12er + tags: | + type=raw,value=${{ needs.release.outputs.new_release_major_version }} + type=raw,value=${{ needs.release.outputs.new_release_major_version }}.${{ needs.release.outputs.new_release_minor_version }} + type=raw,value=${{ needs.release.outputs.new_release_version }} + type=raw,value=latest + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + platforms: linux/amd64 + push: true + tags: ${{ steps.docker_meta.outputs.tags }} + labels: ${{ steps.docker_meta.outputs.labels }} diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..e89631e --- /dev/null +++ b/.releaserc @@ -0,0 +1,10 @@ +{ + "branches": [ + "main" + ], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + "@semantic-release/github", + ] +} diff --git a/Dockerfile b/Dockerfile index e41663a..b240212 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:11 +FROM openjdk:11 as build ENV APP_HOME=/codingpot WORKDIR $APP_HOME @@ -12,4 +12,6 @@ RUN ./gradlew resolveDependencies COPY . $APP_HOME RUN ./gradlew build -ENTRYPOINT java -jar app/build/libs/app.jar +FROM gcr.io/distroless/java:11 +COPY --from=build /codingpot/app/build/libs/app.jar /codingpot/ +CMD ["/codingpot/app.jar"]