From e94e23e5896035a120e20207be30f8daf9eac240 Mon Sep 17 00:00:00 2001 From: Ali Ghanbarzadeh Date: Fri, 21 Apr 2023 13:06:54 +0200 Subject: [PATCH] Add image build workflow --- .github/workflows/.docker/Dockerfile | 11 +++++++++++ .github/workflows/container-build.yaml | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 .github/workflows/.docker/Dockerfile create mode 100644 .github/workflows/container-build.yaml diff --git a/.github/workflows/.docker/Dockerfile b/.github/workflows/.docker/Dockerfile new file mode 100644 index 000000000..ef0439237 --- /dev/null +++ b/.github/workflows/.docker/Dockerfile @@ -0,0 +1,11 @@ +FROM eclipse-temurin:17-jdk-jammy + +WORKDIR /app + +COPY .mvn/ .mvn +COPY mvnw pom.xml ./ +RUN ./mvnw dependency:resolve + +COPY src ./src + +CMD ["./mvnw", "spring-boot:run"] \ No newline at end of file diff --git a/.github/workflows/container-build.yaml b/.github/workflows/container-build.yaml new file mode 100644 index 000000000..f08f76e8e --- /dev/null +++ b/.github/workflows/container-build.yaml @@ -0,0 +1,24 @@ +name: Push to GCR GitHub Action +on: [push] +jobs: + build-and-push-to-gcr: + runs-on: ubuntu-latest + permissions: + contents: 'read' + id-token: 'write' + steps: + - uses: actions/checkout@v3 + - name: 'Authenticate to Google Cloud' + id: auth + uses: 'google-github-actions/auth@v1.0.0' + with: + workload_identity_provider: 'projects/871215665939/locations/global/workloadIdentityPools/github/providers/github' + service_account: push-to-gcr@github-actions-gcp.iam.gserviceaccount.com + - uses: RafikFarhad/push-to-gcr-github-action@v5-beta + with: + registry: gcr.io + project_id: github-actions-gcp + image_name: spring-petclinic-test + image_tag: latest,v1 + dockerfile: ./docker/Dockerfile + context: ./docker \ No newline at end of file