Skip to content

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches:
- main # Trigger the workflow on push to the main branch
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.18'
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build the Go application
run: |
go mod download
CGO_ENABLED=0 GOOS=linux go build -o main .
- name: Build Docker image
run: docker build -t myusername/myapp:latest .
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push Docker image
run: docker push deepanshu2000/guestbook-go:latest