Introduce Automated Docker Build & Push Workflow #1
Workflow file for this run
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 every Sunday | |
- cron: '0 0 * * 0' | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: self-hosted | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Build Docker image (no push) | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
load: true | |
tags: distrolessdevops/nginx-distroless:latest | |
push: | |
runs-on: self-hosted | |
needs: build | |
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' | |
steps: | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: distrolessdevops/nginx-distroless:latest | |
- name: Logout from Docker Hub | |
if: always() | |
run: docker logout |