-
Notifications
You must be signed in to change notification settings - Fork 2
/
Earthfile
138 lines (103 loc) · 3.35 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
FROM busybox:1.32
test-and-build:
# target running tests and building image
BUILD +test-all
BUILD +prepare-image
release:
# uploads the image to registry
BUILD +test-all
BUILD +build-image
dependencies:
# copy relevant files in, save as a base image
FROM +sbt
# create user & working dir for sbt
ARG BUILD_DIR="/build"
USER root
RUN mkdir $BUILD_DIR && \
chmod 777 /$BUILD_DIR
WORKDIR $BUILD_DIR
# copy configurations
COPY .scalafmt.conf build.sbt .
COPY --dir project .
# clean & install dependencies
RUN sbt clean cleanFiles update
code:
FROM +dependencies
# copy proto definitions & generate
COPY --dir proto .
RUN sbt protocGenerate
# copy code
COPY --dir code .
compile:
# package the jars/executables
FROM +code
RUN sbt stage
RUN chmod -R u=rX,g=rX target/universal/stage
SAVE ARTIFACT target/universal/stage/ /target
prepare-image:
# bundle into a slimmer, runnable container
FROM openjdk:11-jre-slim
USER root
# create cos user for the service
RUN groupadd -r cos && useradd --gid cos -r --shell /bin/false cos
# copy over files
WORKDIR /opt/docker
COPY --chown cos:root +compile/target .
# set runtime user to cos
USER cos
ENTRYPOINT /opt/docker/bin/entrypoint
CMD []
build-image:
FROM +prepare-image
# build the image and push remotely (if all steps are successful)
ARG VERSION=dev
SAVE IMAGE --push namely/chief-of-state:${VERSION}
test-local:
FROM +code
# enable coverage mode and compile tests
RUN sbt coverage test:compile compile
# run with docker to enable testcontainers
WITH DOCKER
RUN sbt coverage test coverageAggregate
END
# push to earthly cache
SAVE IMAGE --push namely/chief-of-state:earthly-cache
test-all:
BUILD +test-local
sbt:
# TODO: move this to a central image
FROM openjdk:11-jdk-stretch
USER root
# create directories
RUN mkdir /sbt && chmod 777 /sbt
RUN mkdir /logs && chmod 777 /logs
# Install sbt
ARG SBT_VERSION=1.5.5
ARG SBT_URL="https://github.com/sbt/sbt/releases/download/v$SBT_VERSION/sbt-$SBT_VERSION.tgz"
# Install sbt, add symlink
RUN \
curl -fsL "$SBT_URL" | tar xfz - -C /usr/share && \
chown -R root:root /usr/share/sbt && \
chmod -R 755 /usr/share/sbt && \
chmod +x /usr/share/sbt && \
ln -s /usr/share/sbt/bin/sbt /usr/local/bin/sbt
# Switch working directory
WORKDIR /sbt
# This triggers a bunch of useful downloads.
RUN sbt sbtVersion
# install docker tools
# https://docs.docker.com/engine/install/debian/
RUN apt-get remove -y docker docker-engine docker.io containerd runc || true
RUN apt-get update
RUN apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
RUN echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
RUN apt-get update
RUN apt-get install -y docker-ce docker-ce-cli containerd.io