Skip to content

Commit 42397e0

Browse files
committed
Back to dockerfile in ci
1 parent 9a7c2a4 commit 42397e0

File tree

4 files changed

+314
-106
lines changed

4 files changed

+314
-106
lines changed

.circleci/config.yml

Lines changed: 150 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,126 +2,176 @@ version: 2.1
22
executors:
33
my-executor:
44
docker:
5-
- image: circleci/rust:1.32.0-stretch
5+
- image: docker:stable-git
66

7-
jobs:
8-
build:
9-
docker:
10-
- image: circleci/rust:1.32.0-stretch
7+
commands:
8+
##########################
9+
# Getting into the remote container
10+
##########################
11+
copy-into-container:
1112
steps:
12-
- checkout
13+
# https://circleci.com/docs/2.0/building-docker-images/#mounting-folders
1314
- run:
14-
name: Version information
15-
command: rustc --version; cargo --version; rustup --version
15+
name: Copy app directory into dev container
16+
command: |
17+
docker create -v /home/dark/dark-cli --name vols alpine:3.4 /bin/true
18+
docker cp . vols:/home/dark/dark-cli
19+
# set the ownership of all this
20+
docker run -i --volumes-from vols alpine sh -c "adduser -D -u 1000 dark; chown -R dark /home/dark/app"
21+
22+
##########################
23+
# Artifacts
24+
##########################
25+
extract-and-save-artifacts:
26+
steps:
1627
- run:
17-
name: Calculate dependencies
18-
command: cargo generate-lockfile
19-
- restore_cache:
20-
name: "Cargo.lock cache"
21-
keys:
22-
- v1-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
28+
name: Copy out artifacts
29+
when: always
30+
command: |
31+
mkdir -p artifacts
32+
docker cp vols:/home/dark/dark-cli/target artifacts/target
33+
- store_artifacts:
34+
path: artifacts
35+
36+
37+
##########################
38+
# Caches
39+
##########################
40+
clean-caches:
41+
parameters:
42+
path:
43+
type: string
44+
steps:
2345
- run:
24-
name: build-container
25-
command: docker build -t dark-cli .
46+
name: maybe clear caches
47+
# since we don't checksum the cache on its contents, it may
48+
# continue to grow. as a result, let's clear the cache weekly.
49+
# we store the day the cache was built in the cache. if the
50+
# cache was built on friday, and today is not friday, then
51+
# it's the first build after last week, and clear it.
52+
command: |
53+
if [[ `date +"%a"` != "friday" && `cat << parameters.path >>/cache_day` == "friday" ]]; then
54+
echo "clearing caches"
55+
rm -rf << parameters.path >>
56+
else
57+
echo "not clearing caches"
58+
fi
59+
mkdir -p << parameters.path >>
60+
date +"%a" > << parameters.path >>/cache_day
61+
62+
##########################
63+
# Initializing the containers
64+
##########################
65+
initialize:
66+
steps:
67+
- setup_remote_docker:
68+
docker_layer_caching: true
69+
70+
# Save the docker env: type .docker-env when sshing in, then you can
71+
# use ./scripts/run-in-docker
72+
- run: |
73+
env \
74+
| grep 'DOCKER\|NO_PROXY' \
75+
| sed 's/^/export /' \
76+
> /root/docker-env
77+
2678
- run:
27-
name: Build all targets
28-
command: docker run -it dark-cli build --release
29-
- persist_to_workspace:
30-
root: "."
31-
paths:
32-
- /usr/local/cargo/registry
33-
- target/debug/.fingerprint
34-
- target/debug/build
35-
- target/debug/deps
36-
- target/x86_64-pc-windows-gnu/.fingerprint
37-
- target/x86_64-pc-windows-gnu/build
38-
- target/x86_64-pc-windows-gnu/deps
39-
- target/x86_64-apple-darwin-gnu/.fingerprint
40-
- target/x86_64-apple-darwin-gnu/build
41-
- target/x86_64-apple-darwin-gnu/deps
42-
- target/x86_64-unknown-linux-musl/.fingerprint
43-
- target/x86_64-unknown-linux-musl/build
44-
- target/x86_64-unknown-linux-musl/deps
45-
- target/x86_64-unknown-linux-gnu/.fingerprint
46-
- target/x86_64-unknown-linux-gnu/build
47-
- save_cache:
48-
name: "Cargo.lock cache"
49-
paths:
50-
- /usr/local/cargo/registry
51-
- target/debug/.fingerprint
52-
- target/debug/build
53-
- target/debug/deps
54-
key: v1-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
79+
name: Install outer container utilities
80+
# coreutils for gnu date
81+
command: |
82+
apk add --update bash coreutils nginx jq
5583
56-
test:
57-
docker:
58-
- image: circleci/rust:1.32.0-stretch
84+
- run:
85+
name: "Setup cache names"
86+
command: |
87+
date +"%F" > today-timestamp
88+
date +"%F" -d "today - 1 days" > minus1-timestamp
89+
date +"%F" -d "today - 2 days" > minus2-timestamp
90+
date +"%F" -d "today - 3 days" > minus3-timestamp
91+
92+
93+
##########################
94+
# misc
95+
##########################
96+
run-background-container:
5997
steps:
60-
- checkout
6198
- run:
62-
name: Version information
63-
command: rustc --version; cargo --version; rustup --version
99+
name: Build container if necessary
100+
command: docker build -t dark-cli .
101+
- run:
102+
name: Run background container
103+
command: docker run --rm --name dark-cli-ctr -it dark-cli
104+
background: true
105+
wait-for-container:
106+
steps:
64107
- run:
65-
name: Calculate dependencies
66-
command: cargo generate-lockfile
108+
name: "Wait for container"
109+
command: |
110+
# --foreground because this is run in a script by circle
111+
timeout --foreground 5m scripts/wait-until-container-ready
112+
113+
##########################
114+
# Actual workflow
115+
##########################
116+
jobs:
117+
build-dark-cli:
118+
executor: my-executor
119+
steps:
120+
- checkout
121+
- initialize
67122
- restore_cache:
68-
name: "Cargo.lock cache"
69123
keys:
70-
- v1-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
124+
- v10-dark-cli-{{ checksum "dark-cli/Cargo.lock" }}
125+
- v10-dark-cli-{{ checksum "today-timestamp" }}
126+
- v10-dark-cli-{{ checksum "minus1-timestamp" }}
127+
- v10-dark-cli-{{ checksum "minus2-timestamp" }}
128+
- v10-dark-cli-{{ checksum "minus3-timestamp" }}
129+
- clean-caches: { path: "dark-cli/target" }
130+
- clean-caches: { path: "cargo" }
71131
- run:
72-
name: build-container
73-
command: docker build -t dark-cli .
132+
name: Set up volume for cargo
133+
command: |
134+
docker create -v /usr/local/cargo --name dark_rust_cargo alpine:3.4 /bin/true
135+
docker cp cargo dark_rust_cargo:/usr/local/cargo
136+
docker run -i --volumes-from dark_rust_cargo alpine sh -c "adduser -D -u 1000 dark; chown -R dark /usr/local/cargo"
137+
rm -Rf cargo
74138
- run:
75-
name: Build all targets
76-
command: docker run -it dark-cli build --release
77-
- persist_to_workspace:
78-
root: "."
139+
name: Set up volume for target
140+
command: |
141+
docker create -v /home/dark/app/dark-cli-target --name dark_cli_target alpine:3.4 /bin/true
142+
docker cp dark-cli/target dark_cli_target:/home/dark/dark-cli/target
143+
docker run -i --volumes-from dark_cli_target alpine sh -c "adduser -D -u 1000 dark; chown -R dark /home/dark/app/dark-cli/target"
144+
rm -Rf dark-cli
145+
- copy-into-container
146+
- run: ./test
147+
- run:
148+
name: Copy out generated files and caches
149+
command: |
150+
docker cp vols:/home/dark/dark-cli/target dark-cli
151+
docker cp dark_rust_cargo:/usr/local/cargo cargo
152+
- save_cache:
153+
name: "Save cargolock-specific dark-cli cache"
79154
paths:
80-
- /usr/local/cargo
81-
- target/debug/.fingerprint
82-
- target/debug/build
83-
- target/debug/deps
84-
- target/x86_64-pc-windows-gnu/.fingerprint
85-
- target/x86_64-pc-windows-gnu/build
86-
- target/x86_64-pc-windows-gnu/deps
87-
- target/x86_64-apple-darwin-gnu/.fingerprint
88-
- target/x86_64-apple-darwin-gnu/build
89-
- target/x86_64-apple-darwin-gnu/deps
90-
- target/x86_64-unknown-linux-musl/.fingerprint
91-
- target/x86_64-unknown-linux-musl/build
92-
- target/x86_64-unknown-linux-musl/deps
93-
- target/x86_64-unknown-linux-gnu/.fingerprint
94-
- target/x86_64-unknown-linux-gnu/build
95-
- target/x86_64-unknown-linux-gnu/deps
155+
- dark-cli/target
156+
- cargo
157+
key: v10-dark-cli-{{ checksum "dark-cli/Cargo.lock" }}
96158
- save_cache:
97-
name: "Cargo.lock cache"
98-
key: v1-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
159+
name: "Save daily dark-cli cache"
99160
paths:
161+
- dark-cli/target
100162
- cargo
101-
- target/debug/.fingerprint
102-
- target/debug/build
103-
- target/debug/deps
104-
- target/x86_64-pc-windows-gnu/.fingerprint
105-
- target/x86_64-pc-windows-gnu/build
106-
- target/x86_64-pc-windows-gnu/deps
107-
- target/x86_64-apple-darwin-gnu/.fingerprint
108-
- target/x86_64-apple-darwin-gnu/build
109-
- target/x86_64-apple-darwin-gnu/deps
110-
- target/x86_64-unknown-linux-musl/.fingerprint
111-
- target/x86_64-unknown-linux-musl/build
112-
- target/x86_64-unknown-linux-musl/deps
113-
- target/x86_64-unknown-linux-gnu/.fingerprint
114-
- target/x86_64-unknown-linux-gnu/build
115-
- target/x86_64-unknown-linux-gnu/deps
116-
- run:
117-
name: Run all tests
118-
command: docker run -it dark-cli test
163+
key: v10-dark-cli-{{ checksum "today-timestamp" }}
164+
- persist_to_workspace:
165+
root: "."
166+
paths:
167+
- dark-cli/target/x86_64-apple-darwin/release/dark-cli
168+
- dark-cli/target/x86_64-pc-windows-gnu/release/dark-cli
169+
- dark-cli/target/x86_64-unknown-linux-gnu/release/dark-cli
170+
- dark-cli/target/x86_64-unknown-linux-musl/release/dark-cli
119171

120172
workflows:
121173
version: 2
122174
build-and-deploy:
123175
jobs:
124-
- test
125-
- build
126-
127-
# we need an actual deploy here
176+
# initial builds & tests
177+
- build-dark-cli

0 commit comments

Comments
 (0)