-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from tejastn10/feat/optimize-image
Feat: Optimize Docker image
- Loading branch information
Showing
2 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
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
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 }} |
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
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 | ||
|
||
# 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"] |