ci: workflow with docker images #31
This file contains hidden or 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: Build and Release | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| build-and-release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Required to push tags and create releases | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch all history for proper tagging | |
| token: ${{ secrets.GITHUB_TOKEN }} # Use token for authentication | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libgl1-mesa-dev xorg-dev | |
| - name: Generate version tag | |
| id: version | |
| run: | | |
| # Generate version based on timestamp and short commit hash | |
| VERSION="v$(date +'%Y.%m.%d')-$(git rev-parse --short HEAD)" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Generated version: $VERSION" | |
| - name: Build binaries for multiple platforms | |
| run: | | |
| go mod download | |
| # Build for Linux (amd64) | |
| GOOS=linux GOARCH=amd64 go build -o notificator-linux-amd64 . | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: soulkyu | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push Docker images | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| # Build and push WebUI image | |
| docker build -t soulkyu/notificator-webui:${VERSION} -t soulkyu/notificator-webui:latest -f Dockerfile.webui . | |
| docker push soulkyu/notificator-webui:${VERSION} | |
| docker push soulkyu/notificator-webui:latest | |
| # Build and push Backend image | |
| docker build -t soulkyu/notificator-backend:${VERSION} -t soulkyu/notificator-backend:latest -f Dockerfile.backend . | |
| docker push soulkyu/notificator-backend:${VERSION} | |
| docker push soulkyu/notificator-backend:latest | |
| # Build and push Alertmanager image | |
| cd alertmanager/fake | |
| docker build -t soulkyu/notificator-alertmanager:${VERSION} -t soulkyu/notificator-alertmanager:latest -f Dockerfile . | |
| docker push soulkyu/notificator-alertmanager:${VERSION} | |
| docker push soulkyu/notificator-alertmanager:latest | |
| - name: Create and push tag | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git tag ${{ steps.version.outputs.version }} | |
| git push origin ${{ steps.version.outputs.version }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create Release | |
| id: create_release | |
| uses: softprops/action-gh-release@v2 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.version.outputs.version }} | |
| name: Release ${{ steps.version.outputs.version }} | |
| body: | | |
| ## Changes | |
| - Built from commit: ${{ github.sha }} | |
| - Automatic release triggered by push to main | |
| ## Docker Images | |
| Docker images are available on Docker Hub with this version tag: | |
| - `soulkyu/notificator-webui:${{ steps.version.outputs.version }}` | |
| - `soulkyu/notificator-backend:${{ steps.version.outputs.version }}` | |
| - `soulkyu/notificator-alertmanager:${{ steps.version.outputs.version }}` | |
| Also tagged as `:latest` for convenience. | |
| ## Binaries | |
| Multiple platform binaries are attached to this release: | |
| - `notificator-linux-amd64` - Linux x86_64 | |
| draft: false | |
| prerelease: false | |
| files: | | |
| notificator-linux-amd64 |