diff --git a/.gitea/workflows/build-and-deploy.yaml b/.gitea/workflows/build-and-deploy.yaml new file mode 100644 index 0000000..dcfa438 --- /dev/null +++ b/.gitea/workflows/build-and-deploy.yaml @@ -0,0 +1,70 @@ +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.rogi.casa + username: ${{ gitea.actor }} + password: ${{ secrets.RUNNER_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.rogi.casa/${{ gitea.repository_owner }}/myorg-assistant/myorg-assistant:${{ steps.version.outputs.version }} + gitea.rogi.casa/${{ gitea.repository_owner }}/myorg-assistant/myorg-assistant:latest + cache-from: type=registry,ref=gitea.rogi.casa/${{ gitea.repository_owner }}/myorg-assistant/myorg-assistant:latest + cache-to: type=inline + + - name: Checkout k3s-cluster repo + uses: actions/checkout@v4 + with: + repository: roger/k3s-cluster + token: ${{ secrets.RUNNER_GITEA_TOKEN }} + path: k3s-cluster + + - name: Update deployment image tag + run: | + cd k3s-cluster + echo "Updating deployment image to version: ${{ steps.version.outputs.version }}" + # Update the image tag in the deployment file + sed -i "s|image: gitea.rogi.casa/.*/myorg-assistant:.*|image: gitea.rogi.casa/${{ gitea.repository_owner }}/myorg-assistant/myorg-assistant:${{ steps.version.outputs.version }}|g" myorg-assistant/deployment.yaml + # Print the updated image line for verification + grep "image: gitea.rogi.casa/.*/myorg-assistant:" myorg-assistant/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 myorg-assistant/deployment.yaml + git diff --staged --quiet || git commit -m "Update myorg-assistant image to ${{ steps.version.outputs.version }}" + git push