Skip to content

Commit

Permalink
finish docker file for building prod
Browse files Browse the repository at this point in the history
  • Loading branch information
leonlatsch committed Apr 1, 2024
1 parent e780c23 commit 113ca74
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
27 changes: 22 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
FROM alpine:latest
FROM golang:latest as builder
# Define build env
ENV GOOS linux
ENV CGO_ENABLED 0
# Add a work directory
WORKDIR /build
# Cache and install dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy app files
COPY . .
# Build app
RUN go build -o app

WORKDIR /app
FROM alpine:latest as production
# Add certificates
RUN apk add --no-cache ca-certificates
# Copy built binary from builder
COPY --from=builder build/app .
# Expose port
EXPOSE 4000
# Exec built binary
CMD ./app

COPY build/go-resolve /app/go-resolve

ENTRYPOINT [ "/app/go-resolve" ]
18 changes: 9 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash

echo "Cleaning up"
rm -rf build/
mkdir build/

echo "Building executable"
go build -o build/go-resolve

if [[ "$1" == "--docker" ]]; then
if [[ "$1" == "docker" ]]; then
echo "Building docker image"
docker build -t ghcr.io/leonlatsch/go-resolve .
docker build -t ghcr.io/leonlatsch/go-resolve . --target production
else
echo "Cleaning up"
rm -rf build/
mkdir build/

echo "Building executable"
go build -o build/go-resolve
fi

0 comments on commit 113ca74

Please sign in to comment.