feat: overhaul #1
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: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
jobs: | |
build: | |
name: Build Go Application | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
# Set up Go environment | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.21 | |
# Build the application | |
- name: Build Go Application | |
run: | | |
go mod tidy | |
go build -o app . | |
docker-build: | |
name: Build Docker Image | |
runs-on: ubuntu-latest | |
needs: build # Ensure this job runs after "build" | |
steps: | |
# Checkout the repository | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
# Build the Docker image | |
- name: Build Docker Image | |
run: | | |
docker build -t clamav-prometheus-exporter:latest . | |
push: | |
name: Push Docker Image to Docker Hub | |
runs-on: ubuntu-latest | |
needs: [build, docker-build] # Ensure this job runs after "build" and "docker-build" | |
if: github.event_name == 'push' # Only run for "push" events, not "pull_request" | |
steps: | |
# Checkout the repository | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
# Log in to Docker Hub | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
# Push the Docker image | |
- name: Push Docker Image | |
run: | | |
docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/clamav-prometheus-exporter:latest . | |
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/clamav-prometheus-exporter:latest |