-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract docker job into reusable workflow (#938)
* Extractor docker job into reusable workflow * Update visualizer workflow to reuse docker workflow
- Loading branch information
1 parent
a774737
commit 8c78035
Showing
2 changed files
with
78 additions
and
54 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,72 @@ | ||
name: Docker build and docker push (reusable) | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
registry: | ||
description: 'A container registry where the image is stored' | ||
default: 'ghcr.io' | ||
required: false | ||
type: string | ||
organization: | ||
description: 'An organization the image is associated with' | ||
default: 'blockscout' | ||
required: false | ||
type: string | ||
service-name: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 300 | ||
env: | ||
IMAGE_NAME: '${{ inputs.registry }}/${{ inputs.organization }}/${{ inputs.service-name }}' | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- uses: actions-ecosystem/action-regex-match@v2 | ||
id: regex | ||
with: | ||
text: ${{ github.ref }} | ||
regex: '^(refs\/tags\/${{ inputs.service-name }}\/(v\d+\.\d+\.\d+))|(refs\/heads\/(main))$' | ||
|
||
- name: Extract tag name | ||
id: tags_extractor | ||
run: | | ||
t=${{ steps.regex.outputs.group2 }} | ||
m=${{ steps.regex.outputs.group4 }} | ||
(if ! [[ "$t" == "" ]]; then echo tags=${{ env.IMAGE_NAME }}:$t, ${{ env.IMAGE_NAME }}:latest; elif ! [[ "$m" == "" ]]; then echo tags=${{ env.IMAGE_NAME }}:$m; else echo tags=; fi) >> $GITHUB_OUTPUT | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ inputs.registry }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.IMAGE_NAME }} | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Build and push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: ${{ inputs.service-name }} | ||
file: '${{ inputs.service-name }}/Dockerfile' | ||
build-contexts: | | ||
proto=proto | ||
push: ${{ steps.tags_extractor.outputs.tags != '' }} | ||
tags: ${{ steps.tags_extractor.outputs.tags }} | ||
# platforms: | | ||
# linux/amd64 | ||
# linux/arm64/v8 | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:build-cache | ||
cache-to: ${{ github.ref == 'refs/heads/main' && format('type=registry,ref={0}:build-cache,mode=max', env.IMAGE_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