Skip to content

Refactor API config to use runtime environment variables #5

Refactor API config to use runtime environment variables

Refactor API config to use runtime environment variables #5

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
env:
REGISTRY: docker.io
IMAGE_NAME: mariusgeorgescu/bjj-dapp-web
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
NEXT_PUBLIC_API_URL=https://bjjbackend.cardano.vip
NEXT_PUBLIC_PROFILE_POLICY_ID=b831e9c236a1068f969db151a96b92004e8b1eb0ea3f82d6f373eccc
NEXT_PUBLIC_NETWORK_ID=1
API_USER=placeholder
API_PASS=placeholder
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Output image digest
run: echo ${{ steps.build.outputs.digest }}
update-k8s-manifests:
needs: build-and-push
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
steps:
- name: Extract image tag
id: image-tag
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "tag=main-${{ github.sha }}" >> $GITHUB_OUTPUT
echo "branch=main" >> $GITHUB_OUTPUT
else
echo "tag=develop-${{ github.sha }}" >> $GITHUB_OUTPUT
echo "branch=develop" >> $GITHUB_OUTPUT
fi
- name: Checkout k8s configs repository
uses: actions/checkout@v4
with:
repository: mariusgeorgescu/apps-k8s-configs
token: ${{ secrets.K8S_REPO_TOKEN }}
path: k8s-configs
- name: Update bjj-dapp-web image tag
run: |
cd k8s-configs
# Find and update bjj-dapp-web image references
find . -name "*.yaml" -o -name "*.yml" | xargs grep -l "mariusgeorgescu/bjj-dapp-web" | while read file; do
echo "Updating $file"
sed -i "s|mariusgeorgescu/bjj-dapp-web:[^[:space:]]*|mariusgeorgescu/bjj-dapp-web:${{ steps.image-tag.outputs.tag }}|g" "$file"
done
# Check if there are any changes
if git diff --quiet; then
echo "No changes to commit"
exit 0
fi
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
path: k8s-configs
token: ${{ secrets.K8S_REPO_TOKEN }}
commit-message: "Update bjj-dapp-web image to ${{ steps.image-tag.outputs.tag }}"
title: "🚀 Update bjj-dapp-web image to ${{ steps.image-tag.outputs.tag }}"
body: |
## 🐳 Docker Image Update
**Repository:** `mariusgeorgescu/bjj-dapp-web`
**New Tag:** `${{ steps.image-tag.outputs.tag }}`
**Branch:** `${{ steps.image-tag.outputs.branch }}`
**Commit:** `${{ github.sha }}`
### Changes
- Updated bjj-dapp-web image tag in Kubernetes manifests
- Triggered by push to `${{ github.ref_name }}` branch
### Verification
```bash
# Pull the new image
docker pull mariusgeorgescu/bjj-dapp-web:${{ steps.image-tag.outputs.tag }}
```
---
*This PR was automatically created by GitHub Actions*
branch: update-bjj-dapp-web-${{ steps.image-tag.outputs.tag }}
delete-branch: true