forked from spinnaker/deck
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from homedepot/CN-3075-build-docker-gha
[CN-3075] GHA to build and push Docker image to GHCR
- Loading branch information
Showing
8 changed files
with
131 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,60 @@ | ||
name: Branch Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- release-* | ||
workflow_call: | ||
inputs: | ||
BRANCH: | ||
description: "Git branch to fetch code from" | ||
required: true | ||
default: "master" | ||
type: string | ||
|
||
env: | ||
GRADLE_OPTS: -Dorg.gradle.daemon=false -Xmx2g -Xms2g | ||
CONTAINER_REGISTRY: us-docker.pkg.dev/spinnaker-community/docker | ||
NODE_VERSION: 12.16.0 | ||
|
||
permissions: | ||
contents: read | ||
NODE_VERSION: 16.20.2 | ||
|
||
jobs: | ||
branch-build: | ||
# Only run this on repositories in the 'spinnaker' org, not on forks. | ||
if: startsWith(github.repository, 'spinnaker/') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ inputs.BRANCH }} | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- uses: actions/setup-node@v1 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
|
||
- name: Get yarn cache | ||
id: yarn-cache | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
run: | | ||
#echo "::set-output name=dir::$(yarn cache dir)" | ||
echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT | ||
- uses: actions/cache@v1 | ||
- uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.yarn-cache.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- uses: actions/setup-java@v2 | ||
- name: Run install | ||
uses: borales/actions-yarn@v5 | ||
with: | ||
java-version: 11 | ||
distribution: 'zulu' | ||
cache: 'gradle' | ||
|
||
- name: Prepare build variables | ||
id: build_variables | ||
run: | | ||
echo ::set-output name=REPO::${GITHUB_REPOSITORY##*/} | ||
echo ::set-output name=VERSION::"$(git describe --tags --abbrev=0 --match="v[0-9]*" | cut -c2-)-dev-${GITHUB_REF_NAME}-$(git rev-parse --short HEAD)-$(date --utc +'%Y%m%d%H%M')" | ||
- name: Build | ||
env: | ||
ORG_GRADLE_PROJECT_version: ${{ steps.build_variables.outputs.VERSION }} | ||
run: ./gradlew build --stacktrace | ||
|
||
- 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 | ||
cmd: install # will run `yarn install` command | ||
|
||
- name: Run modules | ||
uses: borales/actions-yarn@v5 | ||
with: | ||
registry: us-docker.pkg.dev | ||
username: _json_key | ||
password: ${{ secrets.GAR_JSON_KEY }} | ||
cmd: modules # will run `yarn modules` command | ||
|
||
- 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@v3 | ||
- name: Run build | ||
uses: borales/actions-yarn@v5 | ||
with: | ||
context: . | ||
file: Dockerfile.slim | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: | | ||
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ github.ref_name }}-latest-unvalidated" | ||
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-unvalidated" | ||
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ github.ref_name }}-latest-unvalidated-slim" | ||
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-unvalidated-slim" | ||
cmd: build # will run `yarn build` command | ||
|
||
- 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@v3 | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
context: . | ||
file: Dockerfile.ubuntu | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: | | ||
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ github.ref_name }}-latest-unvalidated-ubuntu" | ||
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-unvalidated-ubuntu" | ||
name: build | ||
path: build/webpack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: "Build Docker image for Deck and push it to GitHub Container Registry" | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
IMAGE_VERSION: | ||
description: "Version to use for image tag" | ||
required: true | ||
default: "0.0.0" | ||
type: string | ||
BRANCH: | ||
description: "Git branch to fetch code from" | ||
required: true | ||
default: "master" | ||
type: string | ||
|
||
env: | ||
CONTAINER_REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository_owner }}/thd-${{ github.event.repository.name }} | ||
|
||
jobs: | ||
push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ inputs.BRANCH }} | ||
|
||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: build | ||
path: build/webpack | ||
|
||
- name: Set release info | ||
run: | | ||
release_version=${{ inputs.IMAGE_VERSION }} | ||
echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV | ||
echo "TAGS=${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:$release_version" >> $GITHUB_ENV | ||
- name: Login | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.CONTAINER_REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up docker context for buildx | ||
id: buildx-context | ||
run: | | ||
docker context create builders | ||
- name: Set up docker buildx | ||
uses: docker/setup-buildx-action@v3 | ||
with: | ||
endpoint: builders | ||
driver-opts: | | ||
image=moby/buildkit:master | ||
- name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
file: "./Dockerfile.ubuntu" | ||
platforms: linux/amd64 | ||
tags: ${{ env.TAGS }} | ||
labels: | | ||
org.opencontainers.image.source=https://github.com/${{ env.IMAGE_NAME }} | ||
org.opencontainers.image.version=${{ env.RELEASE_VERSION }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
BRANCH: | ||
description: 'Git branch to fetch code from' | ||
required: true | ||
default: 'master' | ||
type: string | ||
THD_DECK_VERSION: | ||
description: 'Version of THD Deck' | ||
required: true | ||
default: "0.0.0" | ||
type: string | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/build.yml | ||
with: | ||
BRANCH: ${{ inputs.BRANCH }} | ||
|
||
docker: | ||
needs: build | ||
uses: ./.github/workflows/docker-build.yml | ||
with: | ||
BRANCH: ${{ inputs.BRANCH }} | ||
IMAGE_VERSION: ${{ inputs.THD_DECK_VERSION }} |
Oops, something went wrong.