File tree 3 files changed +37
-21
lines changed
3 files changed +37
-21
lines changed Original file line number Diff line number Diff line change 1
- FROM rust:1 as builder
1
+ FROM rust:1-slim-buster AS base
2
2
3
- COPY . .
3
+ ENV USER=root
4
4
5
- RUN cargo build --release
5
+ WORKDIR /code
6
+ RUN cargo init
7
+ COPY Cargo.toml /code/Cargo.toml
8
+ RUN cargo fetch
6
9
7
- FROM rust:1-slim-stretch
10
+ COPY src /code/src
8
11
9
- COPY --from=builder /target/release/docker_sample .
12
+ CMD [ "cargo" , "test" , "--offline" ]
10
13
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
12
21
13
22
EXPOSE 5000
14
23
15
- ENTRYPOINT ["/ docker_sample" ]
24
+ ENTRYPOINT [ "/usr/bin/ docker_sample" ]
Original file line number Diff line number Diff line change
1
+ # Docker sample
1
2
2
- Build image:
3
+ ## Build image
3
4
4
5
``` shell
5
- docker build -t docker_sample --force-rm --no-cache -f Dockerfile .
6
+ docker build -t docker_sample .
6
7
```
7
8
8
- Run image:
9
+ ## Run built image
9
10
10
11
``` 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
+ ```
18
16
19
- echo " == curl both routes"
20
- curl http://localhost:5000
21
- curl http://localhost:5000/again
17
+ ## Running unit tests
22
18
23
- ```
19
+ ``` shell
20
+ docker build -t docker_sample:test --target base .
21
+ docker run --rm docker_sample:test
22
+ ```
Original file line number Diff line number Diff line change @@ -24,3 +24,11 @@ async fn main() -> std::io::Result<()> {
24
24
. run ( )
25
25
. await
26
26
}
27
+
28
+ #[ cfg( test) ]
29
+ mod tests {
30
+ #[ test]
31
+ fn sample_test ( ) {
32
+ assert ! ( true ) ;
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments