Skip to content

Commit

Permalink
build(docker): update Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadNews committed Jan 17, 2024
1 parent d5a976d commit 83b98a4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ dist/
coverage.txt
coverage.out

# Environments
.env
.env.dev

# vscode
.vscode/*
!.vscode/settings.json
Expand Down
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
# Build the application from source.
FROM golang:1.21.6-alpine@sha256:fd78f2fb1e49bcf343079bbbb851c936a18fc694df993cbddaa24ace0cc724c5 AS go-builder

ENV GOCACHE="/cache/go-build"

WORKDIR /app

COPY go.mod go.sum cmd ./
RUN go build -o /app/dist/deadnews-template-go ./...
RUN --mount=type=cache,target=${GOCACHE} \
go build -o /app/dist/deadnews-template-go ./...

# Deploy the application binary into a lean image.
FROM gcr.io/distroless/static-debian12:latest@sha256:4a2c1a51ae5e10ec4758a0f981be3ce5d6ac55445828463fce8dff3a355e0b75 AS runtime
LABEL maintainer "DeadNews <aurczpbgr@mozmail.com>"

ENV PORT=1271
ENV GO_PORT=1271

COPY --from=go-builder /app/dist/deadnews-template-go /usr/local/bin/deadnews-template-go

USER nonroot:nonroot
EXPOSE ${PORT}
EXPOSE ${GO_PORT}
HEALTHCHECK NONE

CMD ["deadnews-template-go"]
6 changes: 3 additions & 3 deletions cmd/deadnews-template-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (

// This code is the main function of a Go program
// that creates and starts a server using the Echo framework.
// It retrieves the value of the "PORT" environment variable
// It retrieves the value of the "GO_PORT" environment variable
// and if it is not set, it defaults to port 1271.
func main() {
// Create a new Echo instance.
e := makeServer()

// Get the value of the "PORT" environment variable.
httpPort := os.Getenv("PORT")
// Get the value of the "GO_PORT" environment variable.
httpPort := os.Getenv("GO_PORT")
if httpPort == "" {
httpPort = "1271"
}
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ services:
web:
build: .
ports:
- 1271:1271
- 127.0.0.1:${GO_PORT:-1271}:${GO_PORT:-1271}
environment:
PORT: "1271"
GO_PORT: ${GO_PORT:-1271}

0 comments on commit 83b98a4

Please sign in to comment.