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

[WIP] Implement reusable workflow for acr #14

Merged
merged 7 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
72 changes: 72 additions & 0 deletions .github/workflows/build-and-push-image-to-acr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Build and push docker image to Azure Container Registry

on:
workflow_call:
inputs:
APPLICATION_NAME:
required: true
type: string
ACR_NAME:
required: true
type: string
AZURE_CLIENT_ID:
required: true
type: string
AZURE_TENANT_ID:
required: true
type: string
AZURE_SUBSCRIPTION_ID:
required: true
type: string
DOCKERFILE_NAME:
required: false
type: string
DOCKERFILE_PATH:
required: false
type: string
ENVIRONMENT:
required: true
type: string
REGISTRY_URL:
required: true
type: string
RETAG:
required: false
type: boolean
default: true
BUILD_ARG:
required: false
type: string

jobs:
docker:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Az CLI login
uses: azure/login@v2
with:
client-id: ${{ inputs.AZURE_CLIENT_ID }}
tenant-id: ${{ inputs.AZURE_TENANT_ID }}
subscription-id: ${{ inputs.AZURE_SUBSCRIPTION_ID }}
- name: Login to ACR
run: |
az acr login --name ${{ inputs.ACR_NAME }}
- name: Build and push container image
if: ${{ (inputs.ENVIRONMENT != 'prod' && (inputs.RETAG == true || inputs.RETAG == 'true')) || (inputs.RETAG == false || inputs.RETAG == 'false') }}
working-directory: ${{ inputs.DOCKERFILE_PATH }}
run: |
docker build -f ${{ inputs.DOCKERFILE_NAME }} \
-t ${{ inputs.REGISTRY_URL }}/${{ inputs.APPLICATION_NAME }}:$GITHUB_SHA \
. ${{ inputs.BUILD_ARG }}
docker push -a ${{ inputs.REGISTRY_URL }}/${{ inputs.APPLICATION_NAME }}
- name: Retag and push container image
if: ${{ inputs.ENVIRONMENT == 'prod' && (inputs.RETAG == true || inputs.RETAG == 'true') }}
run: |
docker pull ${{ inputs.REGISTRY_URL }}/${{ inputs.APPLICATION_NAME }}:$GITHUB_SHA
docker tag ${{ inputs.REGISTRY_URL }}/${{ inputs.APPLICATION_NAME }}:$GITHUB_SHA ${{ inputs.REGISTRY_URL }}/${{ inputs.APPLICATION_NAME }}:${{ github.ref_name }}
docker push ${{ inputs.REGISTRY_URL }}/${{ inputs.APPLICATION_NAME }}:${{ github.ref_name }}
2 changes: 1 addition & 1 deletion .github/workflows/build-docker-push-to-ecr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Build and push docker image to Azure Container Registry

on:
workflow_call:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/commit-to-helm-chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out application code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Git Commit - get commit author data
run: |-
Expand All @@ -41,7 +41,7 @@ jobs:
echo "COMMIT_AUTHOR=$(git log --format='%an <%ae>' -n 1 HEAD)" >> $GITHUB_ENV

- name: Infrastructure repo checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ inputs.INFRA_REPO }}
ssh-key: ${{ secrets.INFRA_SSH_KEY }}
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# github-workflows
This repository contains a collection of reusable github actions workflows to be used by Cloudkite's clients

* `build-and-push-image-to-acr.yml` - Build and push docker image to Azure Container Registry
* `build-docker-push-to-acr.yml` - Build and push docker image to Elastic Container Registry
* `commit-to-helm-chart-cronjobs.yml` - Commit and push new image tag for a cronjob (standard-app.cronjobs.$CRONJOB_NAME.tag)
* `commit-to-helm-chart.yml` - Commit and push new global image tag for the whole chart (standard-app.tag)