Skip to content

Build and Push Docker Image #6

Build and Push Docker Image

Build and Push Docker Image #6

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
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: Build Docker image
run: |
docker build -t ghcr.io/analyticsmd/github-runner:latest \
-t ghcr.io/analyticsmd/github-runner:${{ github.sha }} \
--platform=linux/amd64 .
- name: Push Docker image
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
docker push ghcr.io/analyticsmd/github-runner:latest
- 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 }}/analyticsmd/github-runner:${{ 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 }}