Skip to content

Commit

Permalink
Merge pull request #4 from tejastn10/feat/optimize-image
Browse files Browse the repository at this point in the history
Feat: Optimize Docker image
  • Loading branch information
tejastn10 authored Dec 5, 2024
2 parents 92c063c + 64ba71d commit d4e4b36
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build and Publish Docker Image

on:
push:
tags:
- "v*.*.*" # Trigger the workflow when a version tag is pushed

jobs:
build:
runs-on: ubuntu-latest

steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v4

# Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Log in to Docker Hub using secrets (DOCKER_USERNAME and DOCKER_PASSWORD
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# Build and push the Docker image with both version and latest tags
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64 # Build only for amd64
tags: |
tejastn10/argus:latest
tejastn10/argus:${{ github.ref_name }}
26 changes: 19 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# Start with the official Go image
FROM golang:1.23
# Stage 1: Build the application
FROM golang:1.23 as builder

Check warning on line 2 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

# Set the working directory
# Set the working directory inside the builder stage
WORKDIR /app

# Copy the Go module files and download dependencies
COPY go.mod go.sum ./
RUN go mod download

# Copy the application code
# Copy the application source code
COPY . .

# Build the Go application
RUN go build -o argus
# Build the Go application statically
RUN CGO_ENABLED=0 GOOS=linux go build -o argus

# Set the default command
# Stage 2: Create a lightweight runtime image
FROM alpine:latest

# Install certificates for HTTPS support
RUN apk add --no-cache ca-certificates

# Set the working directory inside the runtime image
WORKDIR /root/

# Copy the binary from the builder stage
COPY --from=builder /app/argus .

# Set the default command to run the binary
CMD ["./argus"]

0 comments on commit d4e4b36

Please sign in to comment.