Merge pull request #57 from uche-madu/dev #22
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
name: > | |
Retag Airflow Image and Update Values File in | |
the Infrastructure Repository | |
on: | |
push: | |
branches: | |
- main | |
paths: # Only run workflow when Dockerfile or requirements.txt is changed | |
- 'Dockerfile' | |
- 'requirements.txt' | |
env: | |
PROJECT_ID: wizeline-deb | |
GAR_LOCATION: us-central1 | |
REPOSITORY: deb-capstone-airflow-gke | |
IMAGE: airflow2.7.3-custom | |
VALUES_FILE: argocd-app/my-airflow/values-dev.yaml | |
jobs: | |
retag_and_push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
# Configure Workload Identity Federation and generate an access token. | |
- id: 'auth' | |
name: 'Authenticate to Google Cloud' | |
uses: 'google-github-actions/auth@v1' | |
with: | |
token_format: 'access_token' | |
# Replace with values based on setup.sh in dev-infrastructure repo | |
workload_identity_provider: 'projects/734911192367/locations/global/workloadIdentityPools/deb-pool/providers/github-actions' | |
service_account: '[email protected]' | |
- name: Docker login | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev | |
username: 'oauth2accesstoken' | |
password: '${{ steps.auth.outputs.access_token }}' | |
- name: Get last merged PR source branch name | |
id: get-branch-name | |
run: | | |
PR_NUMBER=$(gh pr list --base main --state closed --limit 1 --json number -q ".[0].number") | |
FEATURE_BRANCH_NAME=$(gh pr view $PR_NUMBER --json headRefName -q ".headRefName") | |
echo "Last merged PR number: $PR_NUMBER" | |
echo "Source branch name: $FEATURE_BRANCH_NAME" | |
echo "FEATURE_BRANCH_NAME=$FEATURE_BRANCH_NAME" >> $GITHUB_ENV | |
env: | |
GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
- name: Set SHORT_SHA | |
run: | | |
echo "SHORT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV | |
- name: Retag Docker Image | |
run: | | |
docker pull "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$FEATURE_BRANCH_NAME" | |
docker tag "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$FEATURE_BRANCH_NAME" "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$SHORT_SHA" | |
docker push "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$SHORT_SHA" | |
# Clone the values file from the infrastructure repository | |
- name: Checkout Infrastructure Repository | |
uses: actions/checkout@v4 | |
with: | |
repository: 'uche-madu/deb-infrastructure' | |
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
sparse-checkout: ${{ env.VALUES_FILE }} | |
sparse-checkout-cone-mode: false | |
ref: 'develop' | |
- name: Update values file in Airflow Helm Chart | |
run: | | |
sed -i "s|repository: .*|repository: '$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE'|" $VALUES_FILE | |
sed -i "s|tag: .*|tag: '$SHORT_SHA'|" $VALUES_FILE | |
- name: Commit changes to values file | |
run: | | |
git config --local user.email "${{ secrets.GIT_USER_EMAIL }}" | |
git config --local user.name "${{ secrets.GIT_USER_NAME }}" | |
git add $VALUES_FILE | |
git commit -m "Update image repository and tag in values file to $GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA" | |
git push | |
env: | |
GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |