fix(devops): Dockerfile & .local.env support added
Hello World / hello (push) Has been cancelled
Build / test-and-build (scribblers-linux-x64, ubuntu-latest) (push) Has been cancelled
Build / test-and-build (scribblers-macos-x64, macos-latest) (push) Has been cancelled
Build / test-and-build (scribblers-x64.exe, windows-latest) (push) Has been cancelled
Hello World / hello (push) Has been cancelled
Build / test-and-build (scribblers-linux-x64, ubuntu-latest) (push) Has been cancelled
Build / test-and-build (scribblers-macos-x64, macos-latest) (push) Has been cancelled
Build / test-and-build (scribblers-x64.exe, windows-latest) (push) Has been cancelled
This commit is contained in:
+5
-5
@@ -1,20 +1,20 @@
|
|||||||
# Executable names
|
|
||||||
/scribblers
|
/scribblers
|
||||||
*.exe
|
*.exe
|
||||||
__debug_bin
|
__debug_bin
|
||||||
# IntelliJ state
|
|
||||||
.idea/
|
.idea/
|
||||||
|
.vscode
|
||||||
|
.DS_Store
|
||||||
# Folder that contains code used for trying stuff locally
|
# Folder that contains code used for trying stuff locally
|
||||||
playground/
|
playground/
|
||||||
# Temporary output text files
|
# Temporary output text files
|
||||||
*.out
|
*.out
|
||||||
# System metadata files
|
|
||||||
.DS_Store
|
|
||||||
# Configuration files
|
# Configuration files
|
||||||
.env
|
.local.env
|
||||||
# Anything temporary
|
# Anything temporary
|
||||||
*.tmp
|
*.tmp
|
||||||
# Profiling results
|
# Profiling results
|
||||||
*.pprof
|
*.pprof
|
||||||
# Additional files for hosting. Workaround for now ig.
|
# Additional files for hosting. Workaround for now ig.
|
||||||
public/
|
public/
|
||||||
|
|
||||||
|
|||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
FROM docker.io/golang:1.25.5 AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 1. Cache modules
|
||||||
|
# RUN go env -w GOPROXY=https://package-mirror.liara.ir/repository/go/
|
||||||
|
# RUN go env -w GOSUMDB=off
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download -x
|
||||||
|
|
||||||
|
# 2. Copy source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# 3. Build arguments
|
||||||
|
ARG VERSION="dev"
|
||||||
|
|
||||||
|
# 4. Build the binary
|
||||||
|
ENV CGO_ENABLED=0
|
||||||
|
RUN go build -trimpath -ldflags "-w -s -X 'medad.fun/internal/version.Version=${VERSION}'" -tags timetzdata -o /s ./cmd/main.go
|
||||||
|
|
||||||
|
# -----------------------------------------
|
||||||
|
# Stage 2: Runner
|
||||||
|
# -----------------------------------------
|
||||||
|
FROM scratch
|
||||||
|
|
||||||
|
# 1. Copy the binary (CRITICAL)
|
||||||
|
COPY --from=builder /s /dist
|
||||||
|
|
||||||
|
# 2. Copy public assets (FIXED syntax)
|
||||||
|
COPY .env /.env
|
||||||
|
# COPY --from=builder /public /public
|
||||||
|
|
||||||
|
# 3. Copy SSL certs (UNCOMMENTED)
|
||||||
|
# COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
|
|
||||||
|
# 4. Security
|
||||||
|
USER 248:248
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# 5. Entry point
|
||||||
|
ENTRYPOINT ["/dist"]
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
#
|
|
||||||
# Builder for Golang
|
|
||||||
#
|
|
||||||
# We explicitly use a certain major version of go, to make sure we don't build
|
|
||||||
# with a newer verison than we are using for CI tests, as we don't directly
|
|
||||||
# test the produced binary but from source code directly.
|
|
||||||
FROM docker.io/golang:1.25.5 AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# This causes caching of the downloaded go modules and makes repeated local
|
|
||||||
# builds much faster. We must not copy the code first though, as a change in
|
|
||||||
# the code causes a redownload.
|
|
||||||
COPY go.mod go.sum ./
|
|
||||||
RUN go mod download -x
|
|
||||||
|
|
||||||
# Import that this comes after mod download, as it breaks caching.
|
|
||||||
ARG VERSION="dev"
|
|
||||||
|
|
||||||
# Copy actual codebase, since we only have the go.mod and go.sum so far.
|
|
||||||
COPY . /app/
|
|
||||||
ENV CGO_ENABLED=0
|
|
||||||
RUN go build -trimpath -ldflags "-w -s -X 'github.com/scribble-rs/scribble.rs/internal/version.Version=${VERSION}'" -tags timetzdata -o ./scribblers ./cmd/scribblers
|
|
||||||
|
|
||||||
#
|
|
||||||
# Runner
|
|
||||||
#
|
|
||||||
FROM scratch
|
|
||||||
|
|
||||||
# Additionally hosted files
|
|
||||||
COPY public /public
|
|
||||||
|
|
||||||
COPY --from=builder /app/scribblers /scribblers
|
|
||||||
# The scratch image doesn't contain any certificates, therefore we use
|
|
||||||
# the builders certificate, so that we can send HTTP requests.
|
|
||||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
|
||||||
|
|
||||||
ENTRYPOINT ["/scribblers"]
|
|
||||||
# Random uid to avoid having root privileges. Linux doesn't care that there's no user for it.
|
|
||||||
USER 248:248
|
|
||||||
@@ -133,6 +133,19 @@ func Load() (*Config, error) {
|
|||||||
maps.Copy(envVars, envFileContent)
|
maps.Copy(envVars, envFileContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dotEnvPath = ".local.env"
|
||||||
|
if _, err := os.Stat(dotEnvPath); err != nil {
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
|
return nil, fmt.Errorf("error checking for existence of .local.env file: %w", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
envFileContent, err := gotenv.Read(dotEnvPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error reading .local.env file: %w", err)
|
||||||
|
}
|
||||||
|
maps.Copy(envVars, envFileContent)
|
||||||
|
}
|
||||||
|
|
||||||
// Add local environment variables to EnvVars map
|
// Add local environment variables to EnvVars map
|
||||||
for _, keyValuePair := range os.Environ() {
|
for _, keyValuePair := range os.Environ() {
|
||||||
pair := strings.SplitN(keyValuePair, "=", 2)
|
pair := strings.SplitN(keyValuePair, "=", 2)
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
#
|
|
||||||
# Builder for Golang
|
|
||||||
#
|
|
||||||
# We explicitly use a certain major version of go, to make sure we don't build
|
|
||||||
# with a newer verison than we are using for CI tests, as we don't directly
|
|
||||||
# test the produced binary but from source code directly.
|
|
||||||
FROM docker.io/golang:1.25.5 AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# This causes caching of the downloaded go modules and makes repeated local
|
|
||||||
# builds much faster. We must not copy the code first though, as a change in
|
|
||||||
# the code causes a redownload.
|
|
||||||
COPY go.mod go.sum ./
|
|
||||||
RUN go mod download -x
|
|
||||||
|
|
||||||
# Import that this comes after mod download, as it breaks caching.
|
|
||||||
ARG VERSION="dev"
|
|
||||||
|
|
||||||
# Copy actual codebase, since we only have the go.mod and go.sum so far.
|
|
||||||
COPY . /app/
|
|
||||||
ENV CGO_ENABLED=0
|
|
||||||
RUN go build -trimpath -ldflags "-w -s -X 'github.com/scribble-rs/scribble.rs/internal/version.Version=${VERSION}'" -tags timetzdata -o ./scribblers ./cmd/scribblers
|
|
||||||
|
|
||||||
#
|
|
||||||
# Runner
|
|
||||||
#
|
|
||||||
FROM scratch
|
|
||||||
|
|
||||||
COPY --from=builder /app/scribblers /scribblers
|
|
||||||
# The scratch image doesn't contain any certificates, therefore we use
|
|
||||||
# the builders certificate, so that we can send HTTP requests.
|
|
||||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
|
||||||
|
|
||||||
ENTRYPOINT ["/scribblers"]
|
|
||||||
# Random uid to avoid having root privileges. Linux doesn't care that there's no user for it.
|
|
||||||
USER 248:248
|
|
||||||
Reference in New Issue
Block a user