-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: publshing docker images on master commits, pre-release, and rel…
…ease
- Loading branch information
1 parent
4daeda1
commit 012a906
Showing
9 changed files
with
189 additions
and
116 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ on: | |
branches: | ||
- master | ||
pull_request: | ||
workflow_call: | ||
|
||
permissions: | ||
contents: read | ||
|
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,45 @@ | ||
name: Master CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'master' | ||
- 'master-*' | ||
|
||
jobs: | ||
|
||
run-unit-tests: | ||
name: Run Unit Tests | ||
uses: ./.github/workflows/test.yaml | ||
|
||
generate-tags: | ||
name: Generate Docker Tags | ||
runs-on: ubuntu-latest | ||
outputs: | ||
tag_date: ${{ steps.tag_date.outputs.tag_date }} | ||
short_sha: ${{ steps.short_sha.outputs.short_sha }} | ||
steps: | ||
- name: Generate Tag Date | ||
id: tag_date | ||
run: echo "tag_date=$(date +'%Y%m%d')" >> "$GITHUB_OUTPUT" | ||
- name: Generate Short SHA | ||
id: short_sha | ||
run: echo "short_sha=$(echo $GITHUB_SHA | cut -c1-7)" >> "$GITHUB_OUTPUT" | ||
|
||
publish-docker-image: | ||
name: Publish Docker Image | ||
uses: ./.github/workflows/publish-docker-image.yaml | ||
secrets: inherit | ||
needs: | ||
- run-unit-tests | ||
- generate-tags | ||
permissions: | ||
contents: read | ||
packages: write | ||
with: | ||
images: | | ||
ghcr.io/${{ github.repository }} | ||
# eg: master-20240321-7d8e9f2 | ||
tags: | | ||
type=raw,value=master-${{ needs.generate-tags.outputs.tag_date }}-${{ needs.generate-tags.outputs.short_sha }} | ||
type=raw,value=master-latest |
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,29 @@ | ||
name: Pre-Release CI | ||
|
||
on: | ||
release: | ||
types: | ||
- prereleased | ||
|
||
jobs: | ||
|
||
run-unit-tests: | ||
name: Run Unit Tests | ||
uses: ./.github/workflows/test.yaml | ||
|
||
publish-docker-image: | ||
name: Publish Pre-Release Docker Image | ||
uses: ./.github/workflows/publish-docker-image.yaml | ||
secrets: inherit | ||
needs: | ||
- run-unit-tests | ||
permissions: | ||
contents: read | ||
packages: write | ||
with: | ||
environment: docker-publish | ||
images: | | ||
${{ github.repository }} | ||
ghcr.io/${{ github.repository }} | ||
tags: | | ||
type=raw,value=${{ github.event.release.tag_name }} |
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,30 @@ | ||
name: Release CI | ||
|
||
on: | ||
release: | ||
types: | ||
- released | ||
|
||
jobs: | ||
|
||
run-unit-tests: | ||
name: Run Unit Tests | ||
uses: ./.github/workflows/test.yaml | ||
|
||
publish-docker-image: | ||
name: Publish Pre-Release Docker Image | ||
uses: ./.github/workflows/publish-docker-image.yaml | ||
secrets: inherit | ||
needs: | ||
- run-unit-tests | ||
permissions: | ||
contents: read | ||
packages: write | ||
with: | ||
environment: docker-publish | ||
images: | | ||
${{ github.repository }} | ||
ghcr.io/${{ github.repository }} | ||
tags: | | ||
type=raw,value=${{ github.event.release.tag_name }} | ||
type=raw,value=latest |
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,77 @@ | ||
name: Publish Docker Image | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
environment: | ||
type: string | ||
required: false | ||
description: 'The environment to publish the Docker image to.' | ||
tags: | ||
type: string | ||
required: true | ||
description: 'The tags to apply to the Docker image.' | ||
images: | ||
type: string | ||
required: true | ||
description: 'The images to publish' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build-and-push-image: | ||
name: Build and Push Docker Image | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
environment: ${{ inputs.environment }} | ||
steps: | ||
|
||
- name: Checkout Repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v2 | ||
# Only log in to Docker Hub if the event is a release | ||
if: ${{ inputs.environment == 'docker-publish' }} | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
env: | ||
IMAGES: ${{ inputs.images || format('ghcr.io/{0}', github.repository) }} | ||
TAGS: ${{ inputs.tags || format('type=raw,value={0}-{1}', github.ref, github.sha) }} | ||
with: | ||
# default to ghcr.io for workflow_dispatch | ||
images: ${{ inputs.images || format('ghcr.io/{0}', github.repository) }} | ||
# use the branch + sha if workflow_dispatch | ||
tags: ${{ inputs.tags || format('type=raw,value={0}-{1}', github.ref, github.sha) }} | ||
|
||
- name: Push to Registry(s) | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
provenance: false | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,9 +1,6 @@ | ||
name: Test Docker Buld | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
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,14 +1,10 @@ | ||
name: Unit Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'master' | ||
- 'master-*' | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
workflow_call: | ||
|
||
jobs: | ||
unit_tests: | ||
|
@@ -18,9 +14,9 @@ jobs: | |
os: [ubuntu-latest, macos-latest, windows-latest] | ||
include: | ||
- go-version: 1.19.x | ||
os: ubuntu-latest | ||
os: ubuntu-latest | ||
- go-version: 1.20.x | ||
os: ubuntu-latest | ||
os: ubuntu-latest | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Checkout code | ||
|
@@ -33,11 +29,11 @@ jobs: | |
|
||
- name: Make all | ||
run: make all | ||
|
||
- name: Make Test | ||
id: unit-test | ||
run: make test | ||
|
||
- name: Post To Slack | ||
if: always() && github.ref == 'refs/heads/master' && (steps.unit-test.outcome == 'failure') | ||
uses: slackapi/[email protected] | ||
|
@@ -52,7 +48,7 @@ jobs: | |
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
test_coverage: | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|