From d75a82317daa007b8d79c805d3614cf73d18149c Mon Sep 17 00:00:00 2001 From: David Byron <82477955+dbyron-sf@users.noreply.github.com> Date: Thu, 10 Mar 2022 11:59:38 -0800 Subject: [PATCH] chore(ci): GHA - container image and apt package build & push (#4233) to google artifact registry See https://github.com/spinnaker/rosco/pull/841 and https://github.com/spinnaker/rosco/pull/839 for similar changes. --- .github/workflows/build.yml | 44 +++++++++++++++++++++++++++++-- .github/workflows/pr.yml | 27 ++++++++++++++++++- .github/workflows/release.yml | 49 +++++++++++++++++++++++++++++++++-- 3 files changed, 115 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 62cda62ea8..09df415072 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,10 +4,11 @@ on: push: branches: - master - - version-* + - release-* env: GRADLE_OPTS: -Dorg.gradle.daemon=false -Xmx6g -Xms6g + CONTAINER_REGISTRY: us-docker.pkg.dev/spinnaker-community/docker jobs: branch-build: @@ -21,5 +22,44 @@ jobs: java-version: 11 distribution: 'zulu' cache: 'gradle' + - name: Extract repository name + id: extract_repo_name + run: echo ::set-output name=REPO::${GITHUB_REPOSITORY##*/} - name: Build - run: ./gradlew build --stacktrace + run: ./gradlew build --stacktrace ${{ steps.extract_repo_name.outputs.REPO }}-web:installDist + - name: Get date + id: get_date + run: echo ::set-output name=DATETIME::$(date --utc +'%Y%m%d%H%M') + - name: Login to GAR + # Only run this on repositories in the 'spinnaker' org, not on forks. + if: startsWith(github.repository, 'spinnaker/') + uses: docker/login-action@v1 + # use service account flow defined at: https://github.com/docker/login-action#service-account-based-authentication-1 + with: + registry: us-docker.pkg.dev + username: _json_key + password: ${{ secrets.GAR_JSON_KEY }} + - name: Build and publish slim container image + # Only run this on repositories in the 'spinnaker' org, not on forks. + if: startsWith(github.repository, 'spinnaker/') + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.slim + push: true + tags: | + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ github.ref_name }}-latest-unvalidated" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ github.ref_name }}-${{ github.sha }}-${{ steps.get_date.outputs.DATETIME }}-unvalidated" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ github.ref_name }}-latest-unvalidated-slim" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ github.ref_name }}-${{ github.sha }}-${{ steps.get_date.outputs.DATETIME }}-unvalidated-slim" + - name: Build and publish ubuntu container image + # Only run this on repositories in the 'spinnaker' org, not on forks. + if: startsWith(github.repository, 'spinnaker/') + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.ubuntu + push: true + tags: | + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ github.ref_name }}-latest-unvalidated-ubuntu" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ github.ref_name }}-${{ github.sha }}-${{ steps.get_date.outputs.DATETIME }}-unvalidated-ubuntu" diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 02d922655e..bcdfe38694 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -4,6 +4,7 @@ on: [ pull_request ] env: GRADLE_OPTS: -Dorg.gradle.daemon=false -Xmx6g -Xms6g + CONTAINER_REGISTRY: us-docker.pkg.dev/spinnaker-community/docker jobs: build: @@ -15,5 +16,29 @@ jobs: java-version: 11 distribution: 'zulu' cache: 'gradle' + - name: Extract repository name + id: extract_repo_name + run: echo ::set-output name=REPO::${GITHUB_REPOSITORY##*/} - name: Build - run: ./gradlew build + run: ./gradlew build ${{ steps.extract_repo_name.outputs.REPO }}-web:installDist + - name: Get date + id: get_date + run: echo ::set-output name=DATETIME::$(date --utc +'%Y%m%d%H%M') + - name: Build slim container image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.slim + tags: | + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:latest" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ github.sha }}-${{ steps.get_date.outputs.DATETIME }}" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:latest-slim" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ github.sha }}-${{ steps.get_date.outputs.DATETIME }}-slim" + - name: Build ubuntu container image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.ubuntu + tags: | + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:latest-ubuntu" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ github.sha }}-${{ steps.get_date.outputs.DATETIME }}-ubuntu" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b172b6af1a..6f2bd71f88 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,10 +5,10 @@ on: tags: - "v[0-9]+.[0-9]+.[0-9]+" - "v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+" - - "version-[0-9]+.[0-9]+.[0-9]+" env: GRADLE_OPTS: -Dorg.gradle.daemon=false -Xmx6g -Xms6g -Dorg.gradle.internal.http.socketTimeout=120000 -Dorg.gradle.internal.http.connectionTimeout=120000 -Dorg.gradle.internal.remote.repository.deploy.max.attempts=6 + CONTAINER_REGISTRY: us-docker.pkg.dev/spinnaker-community/docker jobs: release: @@ -31,6 +31,9 @@ jobs: echo ::set-output name=SKIP_RELEASE::${SKIP_RELEASE} echo ::set-output name=IS_CANDIDATE::${IS_CANDIDATE} echo ::set-output name=RELEASE_VERSION::${RELEASE_VERSION} + - name: Extract repository name + id: extract_repo_name + run: echo ::set-output name=REPO::${GITHUB_REPOSITORY##*/} - name: Release build env: ORG_GRADLE_PROJECT_version: ${{ steps.release_info.outputs.RELEASE_VERSION }} @@ -40,7 +43,49 @@ jobs: ORG_GRADLE_PROJECT_nexusPgpSigningKey: ${{ secrets.NEXUS_PGP_SIGNING_KEY }} ORG_GRADLE_PROJECT_nexusPgpSigningPassword: ${{ secrets.NEXUS_PGP_SIGNING_PASSWORD }} run: | - ./gradlew --info publishToNexus closeAndReleaseNexusStagingRepository + ./gradlew --info build ${{ steps.extract_repo_name.outputs.REPO }}-web:installDist publishToNexus closeAndReleaseNexusStagingRepository + - name: Publish apt packages to Google Artifact Registry + env: + ORG_GRADLE_PROJECT_version: ${{ steps.release_info.outputs.RELEASE_VERSION }} + ORG_GRADLE_PROJECT_artifactRegistryPublishEnabled: true + GAR_JSON_KEY: ${{ secrets.GAR_JSON_KEY }} + run: | + ./gradlew --info publish + - name: Get date + id: get_date + run: echo ::set-output name=DATETIME::$(date --utc +'%Y%m%d%H%M') + - name: Login to GAR + # Only run this on repositories in the 'spinnaker' org, not on forks. + if: startsWith(github.repository, 'spinnaker/') + uses: docker/login-action@v1 + # use service account flow defined at: https://github.com/docker/login-action#service-account-based-authentication-1 + with: + registry: us-docker.pkg.dev + username: _json_key + password: ${{ secrets.GAR_JSON_KEY }} + - name: Build and publish slim container image + # Only run this on repositories in the 'spinnaker' org, not on forks. + if: startsWith(github.repository, 'spinnaker/') + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.slim + push: true + tags: | + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-unvalidated" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-unvalidated-slim" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-$${{ github.sha }}-{{ steps.get_date.outputs.DATETIME }}-unvalidated-slim" + - name: Build and publish ubuntu container image + # Only run this on repositories in the 'spinnaker' org, not on forks. + if: startsWith(github.repository, 'spinnaker/') + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.ubuntu + push: true + tags: | + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-unvalidated-ubuntu" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.extract_repo_name.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-$${{ github.sha }}-{{ steps.get_date.outputs.DATETIME }}-unvalidated-ubuntu" - name: Create release if: steps.release_info.outputs.SKIP_RELEASE == 'false' uses: actions/create-release@v1