Skip to content

Resructure docker

Resructure docker #12

Workflow file for this run

name: Release to GHCR & Helm Sync
on:
pull_request:
paths:
- pyproject.toml
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.check.outputs.should_skip }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check if pyproject.toml version changed
id: check
run: |
if git rev-parse HEAD^ >/dev/null 2>&1; then
DIFF=$(git diff -U0 HEAD^ -- pyproject.toml)
else
DIFF=$(git show HEAD:pyproject.toml)
fi
echo "DIFF=$DIFF"
if echo "$DIFF" | grep -E '^+\s*version\s*='; then
echo "should_skip=false" >> $GITHUB_OUTPUT
echo "Detected version change. should_skip=false"
else
echo "should_skip=true" >> $GITHUB_OUTPUT
echo "No version change found. should_skip=true"
fi
build-and-push:
name: Build & Push to GHCR using pyproject version
needs: check-version
if: needs.check-version.outputs.should_skip != 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
GHCR_IMAGE: ghcr.io/${{ github.repository }}
outputs:
version: ${{ steps.version.outputs.VERSION }}
image: ${{ steps.version.outputs.IMAGE }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from pyproject.toml
id: version
run: |
VERSION=$(grep -Po '(?<=^version = ")[^"]+' pyproject.toml)
echo "VERSION=$VERSION"
echo "VERSION_TAG=v$VERSION" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "IMAGE=${{ env.GHCR_IMAGE }}" >> $GITHUB_OUTPUT
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker image to GHCR
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ env.GHCR_IMAGE }}:${{ env.VERSION_TAG }}
update-helm-values:
name: Update Helm Values
needs: build-and-push
runs-on: ubuntu-latest
env:
CHART_FILE: deployments/helm-charts/fraud-detection/Chart.yaml
VALUE_FILE: deployments/helm-charts/fraud-detection/values.yaml
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: "${{ github.head_ref || github.ref_name }}"
fetch-depth: 0 # important for PR creation
- name: Set up Git config
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Install yq
run: |
sudo wget https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
- name: Update Chart.yaml & values.yaml with version
run: |
VERSION="v${{ needs.build-and-push.outputs.version }}"
IMAGE="${{ needs.build-and-push.outputs.image }}"
yq eval ".version = \"${VERSION#v}\" |
.appVersion = \"${VERSION#v}\"" \
-i "$CHART_FILE"
yq eval ".image.repository = \"$IMAGE\" |
.image.tag = \"$VERSION\"" \
-i "$VALUE_FILE"
git add "$CHART_FILE" "$VALUE_FILE"
git commit -m "ci: update Helm values.yaml and Chart.yaml to $IMAGE:$VERSION"
git push origin HEAD