Skip to content

Merge pull request #28 from mailsonpeixe/update-go-version #24

Merge pull request #28 from mailsonpeixe/update-go-version

Merge pull request #28 from mailsonpeixe/update-go-version #24

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches:
- master
tags:
- v*
pull_request:
branches:
- master
env:
IMAGE_NAME: clamav-prometheus-exporter
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.23
# 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 . -f Dockerfile -t $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
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"
# Only run for "push" events and on the owner repository, not for "pull_request"
if: github.event_name == 'push' && github.repository_owner == 'r3kzi'
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: |
IMAGE_ID=${{ secrets.DOCKER_HUB_USERNAME }}/$IMAGE_NAME
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=latest
[[ "${{ github.ref_type }}" == "tag" ]] && VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,;s/^v//')
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION