Skip to content

Commit

Permalink
chore(ci): GHA - container image and apt package build & push (#998)
Browse files Browse the repository at this point in the history
to Google Artifact Registry

see: spinnaker/rosco#841
  • Loading branch information
kskewes-sf authored Mar 10, 2022
1 parent 356436d commit 06bfd66
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 10 deletions.
44 changes: 42 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ on:
push:
branches:
- master
- version-*
- release-*

env:
GRADLE_OPTS: -Dorg.gradle.daemon=false -Xmx2g -Xms2g
CONTAINER_REGISTRY: us-docker.pkg.dev/spinnaker-community/docker

jobs:
branch-build:
Expand All @@ -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"
27 changes: 26 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [ pull_request ]

env:
GRADLE_OPTS: -Dorg.gradle.daemon=false -Xmx2g -Xms2g
CONTAINER_REGISTRY: us-docker.pkg.dev/spinnaker-community/docker

jobs:
build:
Expand All @@ -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"
59 changes: 52 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -Xmx2g -Xms2g
CONTAINER_REGISTRY: us-docker.pkg.dev/spinnaker-community/docker

jobs:
release:
Expand All @@ -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 }}
Expand All @@ -40,16 +43,58 @@ 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
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.event.repository.name }} ${{ github.ref }}
body: |
tag_name: ${{ github.ref }}
release_name: ${{ github.event.repository.name }} ${{ github.ref }}
body: |
${{ steps.release_info.outputs.CHANGELOG }}
draft: false
prerelease: ${{ steps.release_info.outputs.IS_CANDIDATE }}
draft: false
prerelease: ${{ steps.release_info.outputs.IS_CANDIDATE }}

0 comments on commit 06bfd66

Please sign in to comment.