Skip to content

Commit 22c8eaa

Browse files
authored
Merge pull request #326 from jdrouet/clean-docker-sample
update docker sample by caching dependencies
2 parents e4b94fc + 1088756 commit 22c8eaa

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

Diff for: docker_sample/Dockerfile

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
FROM rust:1 as builder
1+
FROM rust:1-slim-buster AS base
22

3-
COPY . .
3+
ENV USER=root
44

5-
RUN cargo build --release
5+
WORKDIR /code
6+
RUN cargo init
7+
COPY Cargo.toml /code/Cargo.toml
8+
RUN cargo fetch
69

7-
FROM rust:1-slim-stretch
10+
COPY src /code/src
811

9-
COPY --from=builder /target/release/docker_sample .
12+
CMD [ "cargo", "test", "--offline" ]
1013

11-
RUN ls -la /docker_sample
14+
FROM base AS builder
15+
16+
RUN cargo build --release --offline
17+
18+
FROM rust:1-slim-buster
19+
20+
COPY --from=builder /code/target/release/docker_sample /usr/bin/docker_sample
1221

1322
EXPOSE 5000
1423

15-
ENTRYPOINT ["/docker_sample"]
24+
ENTRYPOINT [ "/usr/bin/docker_sample" ]

Diff for: docker_sample/README.MD

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1+
# Docker sample
12

2-
Build image:
3+
## Build image
34

45
```shell
5-
docker build -t docker_sample --force-rm --no-cache -f Dockerfile .
6+
docker build -t docker_sample .
67
```
78

8-
Run image:
9+
## Run built image
910

1011
```shell
11-
12-
echo "== start sample_docker"
13-
docker run -d -p 5000:5000 docker_sample &
14-
docker ps
15-
16-
echo "== wait 3s for startup"
17-
sleep 3s
12+
docker run -d -p 5000:5000 docker_sample
13+
# and the server should start instantly
14+
curl http://localhost:5000
15+
```
1816

19-
echo "== curl both routes"
20-
curl http://localhost:5000
21-
curl http://localhost:5000/again
17+
## Running unit tests
2218

23-
```
19+
```shell
20+
docker build -t docker_sample:test --target base .
21+
docker run --rm docker_sample:test
22+
```

Diff for: docker_sample/src/main.rs

+8
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ async fn main() -> std::io::Result<()> {
2424
.run()
2525
.await
2626
}
27+
28+
#[cfg(test)]
29+
mod tests {
30+
#[test]
31+
fn sample_test() {
32+
assert!(true);
33+
}
34+
}

0 commit comments

Comments
 (0)