Define Secret #97
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: Main | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- '*' # Triggers both builds and tag deployments | |
jobs: | |
build: | |
name: Build and Test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Extract version from tag | |
id: get_version | |
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
install: true | |
- name: Create Docker Buildx builder | |
run: docker buildx create --use --name mybuilder | |
- name: Generate Docker Compose file | |
run: | | |
pip install jinja2-cli[yaml] | |
jinja2 docker-compose.jinja values.yaml -D version=${{ env.VERSION }} -D production=true > docker-compose.yml | |
- name: Build and push image | |
if: startsWith(github.ref, 'refs/tags/') | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ secrets.DOCKERHUB_USERNAME }}/ris-kafka:latest | |
${{ secrets.DOCKERHUB_USERNAME }}/ris-kafka:${{ env.VERSION }} | |
platforms: linux/amd64 | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: docker-compose.yml | |
path: docker-compose.yml | |
deploy: | |
name: Deploy to GitHub Pages | |
needs: build | |
if: startsWith(github.ref, 'refs/tags/') | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Git user | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Checkout gh-pages branch | |
run: | | |
git fetch --no-tags --filter=blob:none origin gh-pages | |
git checkout gh-pages || git checkout --orphan gh-pages | |
- name: Download Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: docker-compose.yml | |
path: . | |
- name: Commit and Push Changes | |
run: | | |
git add docker-compose.yml | |
git commit -m "Deploy latest docker-compose.yml to GitHub Pages" | |
git push origin gh-pages || echo "No changes to push" |