Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX-480 <svc build and push> #159

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions .github/workflows/build-and-push-docker-image-artifact.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Build And Push Docker Images

on:
workflow_call:
outputs:
image_version:
value: ${{ jobs.buildandpushdocker.outputs.image_version }}
inputs:
dockerfile_path:
required: false
type: string
description: "Path of the dockerfile"
default: "Dockerfile"
image_name:
required: true
type: string
description: "Name of the docker image"
default: ""
platforms:
required: false
type: string
description: "List of image platforms"
default: "linux/amd64"
auth_registry:
required: false
type: string
description: "Registry Address to pull images, used on gcloud auth configure-docker"
default: "eu.gcr.io,europe-west3-docker.pkg.dev"
registry:
required: false
type: string
description: "Registry Address for push images"
default: "eu.gcr.io"
repository:
required: true
type: string
description: "Repository Name"
default: "usc"
project_id:
required: false
type: string
description: "GCP Project ID"
default: "usg-svc"
image_tag:
required: false
type: string
description: "Tag for Docker image"
default: ""
context:
required: false
type: string
description: "Docker build context"
default: "."
target:
required: false
type: string
description: "Sets the target stage to build"
enable_summary:
type: boolean
default: false
required: false
push:
type: boolean
default: true
required: false
secrets:
build_args:
required: false
description: "Build args"
secret_args:
required: false
description: "Secret args to be passed to the docker build"

jobs:
buildandpushdocker:
name: Build and Push
runs-on: [self-hosted, dind]

outputs:
image_version: ${{ steps.subscriber_meta.outputs.version }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: SCE validator
uses: urbansportsclub/usc-github-actions/SCE-validator@main

- name: Docker subscriber meta
id: subscriber_meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.registry }}/${{ inputs.project_id }}/${{ inputs.repository }}/${{ inputs.image_name }}
flavor: |
latest=auto
tags: |
type=raw,priority=10,value=${{ inputs.image_tag }},enable=${{ inputs.image_tag != '' }}
type=semver,priority=20,pattern={{version}}
type=semver,priority=21,pattern=v{{major}}
type=schedule,priority=30
type=sha,priority=40

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: 'europe-west3-docker.pkg.dev/urbansportsclub-dev/docker-hub/tonistiigi/binfmt:latest'
if: inputs.platforms != 'linux/amd64'

- name: Configure Docker Auth
run: |-
gcloud auth configure-docker ${{ inputs.auth_registry }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
install: true
buildkitd-flags: --debug
driver-opts: |
image=europe-west3-docker.pkg.dev/urbansportsclub-dev/docker-hub/moby/buildkit:master

- name: Build and push
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: ${{ inputs.enable_summary }}
with:
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile_path }}
platforms: ${{ inputs.platforms }}
target: ${{ inputs.target }}
build-args: |
${{ secrets.build_args }}
push: ${{ inputs.push }}
tags: ${{ steps.subscriber_meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
secrets: |
${{ secrets.secret_args }}