name: Build and Publish Docker Image on: workflow_dispatch: # Manual trigger push: branches: [ dev ] paths-ignore: - 'README.md' - '**.md' - '.github/workflows/**' # This will make the workflow run after the version bump workflow completes workflow_run: workflows: ["Version Bump"] branches: [main, master] types: - completed jobs: build-and-push: # Only run if the triggering workflow succeeded or if this was triggered directly if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name != 'workflow_run' }} runs-on: ubuntu-latest permissions: contents: read packages: write # Required to push to GitHub Container Registry steps: - name: Checkout code uses: actions/checkout@v4 with: ref: ${{ github.ref }} # Checkout the branch that triggered the workflow fetch-depth: 0 # Fetch all history for all tags and branches - name: Check branch id: check-branch run: | BRANCH_NAME="${GITHUB_REF#refs/heads/}" echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT if [[ "$BRANCH_NAME" == "dev" ]]; then echo "IS_DEV=true" >> $GITHUB_OUTPUT else echo "IS_DEV=false" >> $GITHUB_OUTPUT fi - name: Set up QEMU uses: docker/setup-qemu-action@v3 with: platforms: linux/amd64,linux/arm64,linux/arm/v7 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Generate version info id: version run: | # Get the version from package.json PACKAGE_VERSION=$(node -p "require('./package.json').version") # Generate date-based tag DATE_TAG=$(date +'%Y%m%d') # Get commit count for additional uniqueness COMMIT_COUNT=$(git rev-list --count HEAD) echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT echo "DATE_TAG=${DATE_TAG}" >> $GITHUB_OUTPUT echo "COMMIT_COUNT=${COMMIT_COUNT}" >> $GITHUB_OUTPUT - name: Log in to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata for Docker (Main branch) id: meta-main if: ${{ steps.check-branch.outputs.IS_DEV == 'false' }} uses: docker/metadata-action@v5 with: images: | ${{ secrets.DOCKER_USERNAME }}/trafegodns ghcr.io/${{ github.repository }} tags: | # Latest tag for main/master type=raw,value=latest,enable=true # Package version from package.json type=raw,value=${{ steps.version.outputs.PACKAGE_VERSION }} # Date + commit count for all builds type=raw,value=${{ steps.version.outputs.DATE_TAG }}.${{ steps.version.outputs.COMMIT_COUNT }} # Just date for all builds type=raw,value=${{ steps.version.outputs.DATE_TAG }} - name: Extract metadata for Docker (Dev branch) id: meta-dev if: ${{ steps.check-branch.outputs.IS_DEV == 'true' }} uses: docker/metadata-action@v5 with: images: | ${{ secrets.DOCKER_USERNAME }}/trafegodns ghcr.io/${{ github.repository }} tags: | # Dev tag type=raw,value=dev # Dev with version type=raw,value=dev-${{ steps.version.outputs.PACKAGE_VERSION }} # Dev with date+commit count type=raw,value=dev-${{ steps.version.outputs.DATE_TAG }}.${{ steps.version.outputs.COMMIT_COUNT }} # Build and push multi-arch Docker image for main/master branch - name: Build and push Docker image (Main branch - Multi Architecture) if: ${{ steps.check-branch.outputs.IS_DEV == 'false' }} uses: docker/build-push-action@v6 with: context: . file: ./docker-s6/Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: ${{ steps.meta-main.outputs.tags }} labels: ${{ steps.meta-main.outputs.labels }} cache-from: type=gha # Build and push x64-only Docker image for dev branch - name: Build and push Docker image (Dev branch - x64 only) if: ${{ steps.check-branch.outputs.IS_DEV == 'true' }} uses: docker/build-push-action@v6 with: context: . file: ./docker-s6/Dockerfile platforms: linux/amd64 push: true tags: ${{ steps.meta-dev.outputs.tags }} labels: ${{ steps.meta-dev.outputs.labels }} cache-from: type=gha