-
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.
finish docker file for building prod
- Loading branch information
1 parent
e780c23
commit 113ca74
Showing
2 changed files
with
31 additions
and
14 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 |
---|---|---|
@@ -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" ] |
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,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 |