-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathhost.Dockerfile
47 lines (36 loc) · 1.55 KB
/
host.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
# Build Stages:
# system = prepares the "OS" by downloading required binaries
# get-dependencies = downloads the go modules using the prepared system
# build-host = copies over the source code and builds the binaries using a compiler cache
# final = copies over only the executables in an alpine image that doesn't have any additional load.
FROM golang:1.22.1-alpine3.19 as system
# set the base libs to build / run
RUN apk add build-base bash
ENV CGO_ENABLED=1
FROM system as get-dependencies
# create the base directory
# setup container data structure
RUN mkdir -p /home/obscuro/go-obscuro
# Ensures container layer caching when dependencies are not changed
WORKDIR /home/obscuro/go-obscuro
COPY go.mod .
COPY go.sum .
RUN go mod download
FROM get-dependencies as build-host
# make sure the all code is available
COPY . .
WORKDIR /home/obscuro/go-obscuro/go/host/main
# Build the host executable. Mount cross image build cache to speed up for incremental changes.
RUN --mount=type=cache,target=/root/.cache/go-build \
go build
# Trigger another build stage to remove unnecessary files.
FROM alpine:3.18
# Copy over just the binary from the previous build stage into this one.
COPY --from=build-host \
/home/obscuro/go-obscuro/go/host/main /home/obscuro/go-obscuro/go/host/main
# Workaround to fix postges filepath issue
COPY --from=build-host \
/home/obscuro/go-obscuro/go/host/storage/init/postgres /home/obscuro/go-obscuro/go/host/storage/init/postgres
WORKDIR /home/obscuro/go-obscuro/go/host/main
# expose the http and the ws ports to the host
EXPOSE 8025 9000