-
Notifications
You must be signed in to change notification settings - Fork 9
/
Earthfile
101 lines (89 loc) · 3.56 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
FROM ianpurton/rust-fullstack-devcontainer:latest
ARG EXE_NAME=barricade
ARG FOLDER=.
ARG CONTAINER_NAME=purtontech/barricade
ARG SELENIUM=selenium/standalone-chrome:4.1.1-20220121
WORKDIR /build
npm-deps:
COPY $FOLDER/package.json package.json
COPY $FOLDER/package-lock.json package-lock.json
RUN npm install
SAVE ARTIFACT node_modules
npm-build:
FROM +npm-deps
COPY $FOLDER/asset-pipeline asset-pipeline
COPY +npm-deps/node_modules node_modules
RUN npm run release
SAVE ARTIFACT asset-pipeline/dist
prepare-cache:
COPY --dir $FOLDER/src $FOLDER/Cargo.lock $FOLDER/Cargo.toml .
RUN cargo chef prepare --recipe-path recipe.json
SAVE ARTIFACT recipe.json
build-cache:
COPY +prepare-cache/recipe.json ./
RUN cargo chef cook --release --target x86_64-unknown-linux-musl
SAVE ARTIFACT target
SAVE ARTIFACT $CARGO_HOME cargo_home
SAVE IMAGE --cache-hint
build:
COPY --dir $FOLDER/src $FOLDER/Cargo.lock $FOLDER/Cargo.toml $FOLDER/build.rs .
COPY +build-cache/cargo_home $CARGO_HOME
COPY +build-cache/target target
RUN mkdir asset-pipeline
COPY --dir +npm-build/dist asset-pipeline
RUN cargo build --release --target x86_64-unknown-linux-musl
SAVE ARTIFACT target/x86_64-unknown-linux-musl/release/$EXE_NAME $EXE_NAME
SAVE IMAGE --cache-hint
integration-test:
FROM +build
COPY --dir $FOLDER/tests .
COPY --dir migrations .
COPY +build/$EXE_NAME ./$EXE_NAME
ARG DATABASE_URL=postgresql://postgres:testpassword@localhost:5432
# Env vars used by the integration tests
ARG WEB_DRIVER_URL=http://localhost:4444
ARG WEB_DRIVER_DESTINATION_HOST=http://localhost:9095
# Env vars for the app
ARG SECRET_KEY=50fb08b06b381c575e60c56328f66a51822320e922c7e11e264a7bb443ee22fe
ARG FORWARD_URL=localhost
ARG FORWARD_PORT=80
ARG REDIRECT_URL=/
ARG ENABLE_EMAIL_OTP='true'
ARG ENABLE_HEADLESS=1
ARG PORT=9095
ARG USER_TABLE_NAME=bcrypt_users
ARG WEB_DRIVER_DESTINATION_HOST=http://localhost:9096
USER root
WITH DOCKER \
--pull postgres:alpine \
--pull containous/whoami \
# Record our selenium session
--pull $SELENIUM
RUN \
docker run --name whoami -d --rm --network=host containous/whoami \
# Run up postgres
&& docker run -d --rm --network=host -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=testpassword postgres:alpine \
# Run the database migrations
&& while ! pg_isready --host=localhost --port=5432 --username=postgres; do sleep 1; done ;\
diesel migration run \
&& chmod +x ./$EXE_NAME \
# Now the database is up start the exe in normal mode
&& ./$EXE_NAME & \
# Start exe in encrypted mode
PORT=9096 USER_TABLE_NAME=keypair_users AUTH_TYPE=encrypted ./$EXE_NAME & \
# Run up selenium for browser testing.
docker run -d --rm --network=host --name selenium --shm-size="2g" $SELENIUM \
# Finally run the browser testing
&& cargo test --release --target x86_64-unknown-linux-musl -- --nocapture
END
SAVE ARTIFACT ./$EXE_NAME $EXE_NAME
SAVE IMAGE --cache-hint
# The final stage after testing, build our tiny container
docker:
FROM scratch
COPY +integration-test/$EXE_NAME barricade
COPY --dir +npm-build/dist asset-pipeline/dist
EXPOSE 8080
ENTRYPOINT ["./barricade"]
# We call the image build and let semantic release handle tagging and pushing latest
SAVE IMAGE --push $CONTAINER_NAME:build