Skip to content

Commit

Permalink
refactor: Consolidate Dockerfile for production and development envir…
Browse files Browse the repository at this point in the history
…onments
  • Loading branch information
idylicaro committed Dec 27, 2024
1 parent c643be2 commit 27ceb78
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd-docker-hub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile.production
file: ./Dockerfile
target: production
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
30 changes: 29 additions & 1 deletion Dockerfile.development → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,34 @@ RUN swag init
# Build the Go binary
RUN go build -o main .


# Production stage: Create a lightweight runtime image for production
FROM debian:bullseye-slim AS production

# Install necessary libraries (e.g., libc6) to run the Go binary
RUN apt-get update && \
apt-get install -y libc6

# Set the working directory for the application in the container
WORKDIR /app

# Copy the compiled Go binary from the builder stage
COPY --from=builder /app/main .
# Copy the Swagger documentation from the builder stage
COPY --from=builder /app/docs /app/docs

# Set the environment variable for production
ENV ENVIRONMENT=production

# Expose port 8080 for the application
EXPOSE 8080

# Make the Go binary executable
RUN chmod +x /app/main

# Set the entry point to the Go binary for production
ENTRYPOINT ["/app/main"]

# Development stage: Create a lightweight runtime image for development
FROM debian:bullseye-slim AS development

Expand Down Expand Up @@ -47,4 +75,4 @@ EXPOSE 8080
RUN chmod +x /app/main

# Set the entry point to the Go binary for development
ENTRYPOINT ["/app/main"]
ENTRYPOINT ["/app/main"]
48 changes: 0 additions & 48 deletions Dockerfile.production

This file was deleted.

2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
app:
build:
context: .
dockerfile: Dockerfile.development
dockerfile: Dockerfile
target: ${ENVIRONMENT}
ports:
- "8080:8080"
Expand Down

0 comments on commit 27ceb78

Please sign in to comment.