-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathDockerfile
68 lines (51 loc) · 2.02 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Stage 1: Build the Go application
FROM golang:1.22.2-bullseye AS builder
# Set the working directory inside the container
WORKDIR /app
# NOTE: Install necessary libraries for SQLite
RUN apt-get update && apt-get install -y \
gcc \
musl-dev \
sqlite3 \
libsqlite3-dev
# Copy Go modules and download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code
COPY . .
# Build the application
RUN CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -gcflags=all=-l -o /app/goship-web ./cmd/web/main.go
RUN CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -gcflags=all=-l -o /app/goship-worker ./cmd/worker/main.go
RUN CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -gcflags=all=-l -o /app/goship-seed ./cmd/seed/main.go
# Install asynq tools
RUN go install github.com/hibiken/asynq/tools/asynq@latest
################################################
# Stage 2: Create a smaller runtime image
################################################
FROM ubuntu:22.04
# Install necessary packages
RUN apt-get update && apt-get install -y \
curl
# Copy the compiled binaries from the builder image
COPY --from=builder /app/goship-web /goship-web
COPY --from=builder /app/goship-worker /goship-worker
COPY --from=builder /app/goship-seed /goship-seed
# Copy asynq tool
COPY --from=builder /go/bin/asynq /usr/local/bin/
# Copy the templates
COPY templates/ /app/templates/
# Optional: Bind to a TCP port (document the ports the application listens on)
EXPOSE 8000
EXPOSE 8080
# Define an entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
COPY config/config.yaml .
COPY service-worker.js /service-worker.js
COPY static /static
# Below is only used if you need to use PWABuilder to make a native Android app
# RUN mkdir pwabuilder-android-wrapper
# COPY pwabuilder-android-wrapper/assetlinks.json pwabuilder-android-wrapper/assetlinks.json
ENTRYPOINT ["/entrypoint.sh"]
# Clean up any unnecessary files
RUN apt-get purge -y gcc musl-dev libsqlite3-dev && apt-get autoremove -y && apt-get clean