-
Notifications
You must be signed in to change notification settings - Fork 1
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 #12 from infralovers/refactor-container-flow
fix(workflows): Refactor container flow
- Loading branch information
Showing
4 changed files
with
118 additions
and
141 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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
--- | ||
|
||
name: Container Workflow template" | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
dockerfile: | ||
description: 'The path to the Dockerfile' | ||
required: true | ||
type: string | ||
default: 'Dockerfile' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
needs: [ prebuild ] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: go-semantic-release/action@v1 | ||
id: semrel | ||
with: | ||
github-token: ${{ secrets.BOT_ACCESS_TOKEN }} | ||
prepend: true | ||
dry: true | ||
|
||
- name: Get directory of ${{ inputs.dockerfile }} | ||
id: get_dir | ||
run: | | ||
echo "docker_directory=$(dirname ${{ inputs.dockerfile }})" >> $GITHUB_OUTPUT | ||
- name: Prepare tagging | ||
id: prep | ||
run: | | ||
IMAGE_NAME=$(basename ${{ github.repository }}) | ||
IMAGE_REPO=${{ github.repository_owner }} | ||
if [[ -n "${{ secrets.IMAGE_NAME }}" ]]; then | ||
IMAGE_NAME="${{ secrets.IMAGE_NAME }}" | ||
fi | ||
if [[ -n "${{ secrets.IMAGE_REPO }}" ]]; then | ||
IMAGE_REPO="${{ secrets.IMAGE_REPO }}" | ||
fi | ||
VERSION="dev" | ||
if [[ '${{ needs.prebuild.outputs.version }}' != '' ]]; then | ||
VERSION="${{ needs.prebuild.outputs.version }}" | ||
fi | ||
if [ "${{ github.event_name }}" = "schedule" ]; then | ||
VERSION="nightly" | ||
fi | ||
GHCR_IMAGE="ghcr.io/${{ github.repository }}" | ||
TAGS="${GHCR_IMAGE}:${VERSION}" | ||
if [[ -n "${{ env.QUAY_USER }}"]]; then | ||
QUAY_IMAGE="quay.io/$IMAGE_REPO/$IMAGE_NAME" | ||
tags="${TAGS}:${QUAY_IMAGE}:${VERSION}"" | ||
fi | ||
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | ||
TAGS="$TAGS,${GHCR_IMAGE}:latest" | ||
if [[ -n "${{ env.QUAY_USER }}" ]]; then | ||
TAGS="$TAGS,${QUAY_IMAGE}:latest" | ||
fi | ||
fi | ||
echo "settings tag ${TAGS}" | ||
echo "tags=${TAGS}" >> $GITHUB_OUTPUT | ||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
with: | ||
platforms: ${{ env.platforms }} | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Login to Quay | ||
if: needs.prebuild.outputs.version != '' && env.QUAY_USER != '' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: quay.io | ||
username: ${{ env.QUAY_USER }} | ||
password: ${{ env.QUAY_TOKEN }} | ||
|
||
- name: Login to GitHub Container Registry | ||
if: needs.prebuild.outputs.version != '' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ env.BOT_ACCESS_TOKEN }} | ||
|
||
- name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v5 | ||
with: | ||
builder: ${{ steps.buildx.outputs.name }} | ||
context: ${{ steps.get_dir.outputs.docker_directory }} | ||
file: ${{ inputs.dockerfile }} | ||
push: ${{ github.event_name != 'pull_request' && needs.prebuild.outputs.version != '' }} | ||
tags: ${{ steps.prep.outputs.tags }} | ||
platforms: ${{ env.platforms }} |
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
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
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