Skip to content

Instantly share code, notes, and snippets.

@kcollasarundell
Created October 14, 2021 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcollasarundell/3f0937b5e1643e48af06d651c9754e94 to your computer and use it in GitHub Desktop.
Save kcollasarundell/3f0937b5e1643e48af06d651c9754e94 to your computer and use it in GitHub Desktop.
# Dockerfile References: https://docs.docker.com/engine/reference/builder/
############################################ MULTI STAGE BUILD PART 1 ##############################################
# Start from golang v1.17 base image
FROM golang:1.17 as builder
# Creating/Cd work directory
WORKDIR /app
# Copying sources
COPY . .
# Run go build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 /usr/local/go/bin/go build -ldflags="-s -w" -o /app/pack-and-go-api .
# Add wait-for-it tool
ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh /app/wait-for-it
RUN chmod +x /app/wait-for-it
############################################ MULTI STAGE BUILD PART 2 ##############################################
# Using bash
FROM bash
# Copying executable
COPY --from=builder /app/pack-and-go-api .
COPY --from=builder /app/.env .
COPY --from=builder /app/wait-for-it .
CMD /app/wait-for-it database:5432 -- /app/pack-and-go-api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment