Build and Push Docker Image #18
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: Build and Push Docker Image | |
on: | |
schedule: | |
# Runs at 00:00 UTC on the 1st and 15th of every month | |
- cron: '0 0 1,15 * *' | |
workflow_dispatch: | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: analyticsmd/github-runner | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.PACKAGES_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64 | |
push: true | |
tags: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} | |
# - name: Send Success Slack notification | |
# if: success() | |
# uses: slackapi/[email protected] | |
# with: | |
# channel-id: 'C0830SADR0X' #devops-github-actions Slack Channel ID | |
# payload: | | |
# { | |
# "text": "Docker Image Build Success", | |
# "blocks": [ | |
# { | |
# "type": "section", | |
# "text": { | |
# "type": "mrkdwn", | |
# "text": "✅ *Docker Image Build Successful*\n*Repository:* ${{ github.repository }}\n*Image:* ${{ env.REGISTRY }}/${{ env.REPO }}:${{ github.sha }}" | |
# } | |
# } | |
# ] | |
# } | |
# env: | |
# SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
# - name: Send Failure Slack notification | |
# if: failure() | |
# uses: slackapi/[email protected] | |
# with: | |
# channel-id: 'C0830SADR0X' #devops-github-actions Slack Channel ID | |
# payload: | | |
# { | |
# "text": "Docker Image Build Failed", | |
# "blocks": [ | |
# { | |
# "type": "section", | |
# "text": { | |
# "type": "mrkdwn", | |
# "text": "❌ *Docker Image Build Failed*\n*Repository:* ${{ github.repository }}\n*Workflow:* ${{ github.workflow }}\n*Error:* Build and push operation failed\n\n*Check the logs:* ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
# } | |
# } | |
# ] | |
# } | |
# env: | |
# SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} |