-
Notifications
You must be signed in to change notification settings - Fork 0
/
Earthfile
94 lines (77 loc) · 2.23 KB
/
Earthfile
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
VERSION 0.8
FROM golang:1.22
ARG --global ROOT_DIR="/workspace"
ARG --global APP_DIR="app"
ARG --global BUILD_DIR="build"
WORKDIR $ROOT_DIR
RUN go env -w GOCACHE=/go-cache
RUN go env -w GOMODCACHE=/gomod-cache
all:
BUILD +test
BUILD +build
BUILD +assets
deps:
COPY ./$APP_DIR/go.mod ./$APP_DIR/go.mod $ROOT_DIR/$APP_DIR
WORKDIR $ROOT_DIR/$APP_DIR
RUN --mount=type=cache,target=/go-cache --mount=type=cache,target=/go-modcache go mod download -x
test:
FROM +deps
COPY ./$APP_DIR $ROOT_DIR/$APP_DIR
WORKDIR $ROOT_DIR/$APP_DIR
RUN go test . -v
build:
FROM +deps
WORKDIR $ROOT_DIR
RUN mkdir -p $ROOT_DIR/$BUILD_DIR
COPY ./$APP_DIR $ROOT_DIR/$APP_DIR
ENV GOOS="linux"
ENV GOARCH="amd64"
ENV CGO_ENABLED="0"
RUN cd $ROOT_DIR/$APP_DIR && \
go build -o "$ROOT_DIR/$BUILD_DIR/app" main.go
SAVE ARTIFACT --keep-ts $ROOT_DIR/$BUILD_DIR/* $ROOT_DIR/$BUILD_DIR/* AS LOCAL ./$BUILD_DIR/
assets:
WORKDIR $ROOT_DIR
RUN mkdir -p $ROOT_DIR/$BUILD_DIR
COPY ./$APP_DIR/styles.css $ROOT_DIR/$BUILD_DIR
COPY ./$APP_DIR/index.html $ROOT_DIR/$BUILD_DIR
SAVE ARTIFACT --keep-ts $ROOT_DIR/$BUILD_DIR/* $ROOT_DIR/$BUILD_DIR/* AS LOCAL ./$BUILD_DIR/
clean:
LOCALLY
RUN rm -r ./$BUILD_DIR
docker-build:
FROM scratch
ARG TAG="latest"
COPY ./passwd /etc/passwd
COPY ./group /etc/group
USER nobody:nogroup
COPY +build$ROOT_DIR/$BUILD_DIR/* /
COPY +assets$ROOT_DIR/$BUILD_DIR/* /
ENV GIN_MODE=release
EXPOSE 3000
ENTRYPOINT ["/app"]
SAVE IMAGE no-registry.local/hello-world:$TAG
docker-run:
LOCALLY
ARG TAG="latest"
ARG EXPOSED_AT="3000"
ARG GIN_MODE=""
IF test "$GIN_MODE" = ""
WITH DOCKER --load=+docker-build
RUN docker run -p $EXPOSED_AT:3000 no-registry.local/hello-world:$TAG
END
ELSE
WITH DOCKER --load=+docker-build
RUN docker run -p $EXPOSED_AT:3000 -e GIN_MODE=$GIN_MODE no-registry.local/hello-world:$TAG
END
END
dockerfile:
ARG TAG="latest"
FROM DOCKERFILE .
SAVE IMAGE no-registry.local/hello-world:$TAG
docker:
BUILD +docker-build
BUILD +docker-run
docker-dev:
BUILD +docker-build
BUILD +docker-run --GIN_MODE="debug"