68 lines
2.3 KiB
YAML
68 lines
2.3 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- master
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: gitea.yourdomain.com # Replace with your Gitea domain
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Extract version from commit
|
|
id: version
|
|
run: |
|
|
# Use short commit SHA as version tag
|
|
VERSION=$(git rev-parse --short HEAD)
|
|
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
|
echo "Building version: ${VERSION}"
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
gitea.yourdomain.com/${{ gitea.repository_owner }}/gym-tracker:${{ steps.version.outputs.version }}
|
|
gitea.yourdomain.com/${{ gitea.repository_owner }}/gym-tracker:latest
|
|
cache-from: type=registry,ref=gitea.yourdomain.com/${{ gitea.repository_owner }}/gym-tracker:latest
|
|
cache-to: type=inline
|
|
|
|
- name: Checkout k3s-cluster repo
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: yourusername/k3s-cluster # Replace with your manifests repo
|
|
token: ${{ secrets.K3S_REPO_TOKEN }}
|
|
path: k3s-cluster
|
|
|
|
- name: Update deployment image tag
|
|
run: |
|
|
cd k3s-cluster
|
|
# Update the image tag in the deployment file
|
|
sed -i "s|image: gitea.yourdomain.com/.*/gym-tracker:.*|image: gitea.yourdomain.com/${{ gitea.repository_owner }}/gym-tracker:${{ steps.version.outputs.version }}|g" gym-tracker/deployment.yaml
|
|
|
|
- name: Commit and push changes
|
|
run: |
|
|
cd k3s-cluster
|
|
git config user.name "Gitea Actions"
|
|
git config user.email "actions@gitea.local"
|
|
git add gym-tracker/deployment.yaml
|
|
git diff --staged --quiet || git commit -m "Update gym-tracker image to ${{ steps.version.outputs.version }}"
|
|
git push
|