-
-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #326 from jdrouet/clean-docker-sample
update docker sample by caching dependencies
- Loading branch information
Showing
3 changed files
with
37 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
FROM rust:1 as builder | ||
FROM rust:1-slim-buster AS base | ||
|
||
COPY . . | ||
ENV USER=root | ||
|
||
RUN cargo build --release | ||
WORKDIR /code | ||
RUN cargo init | ||
COPY Cargo.toml /code/Cargo.toml | ||
RUN cargo fetch | ||
|
||
FROM rust:1-slim-stretch | ||
COPY src /code/src | ||
|
||
COPY --from=builder /target/release/docker_sample . | ||
CMD [ "cargo", "test", "--offline" ] | ||
|
||
RUN ls -la /docker_sample | ||
FROM base AS builder | ||
|
||
RUN cargo build --release --offline | ||
|
||
FROM rust:1-slim-buster | ||
|
||
COPY --from=builder /code/target/release/docker_sample /usr/bin/docker_sample | ||
|
||
EXPOSE 5000 | ||
|
||
ENTRYPOINT ["/docker_sample"] | ||
ENTRYPOINT [ "/usr/bin/docker_sample" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
# Docker sample | ||
|
||
Build image: | ||
## Build image | ||
|
||
```shell | ||
docker build -t docker_sample --force-rm --no-cache -f Dockerfile . | ||
docker build -t docker_sample . | ||
``` | ||
|
||
Run image: | ||
## Run built image | ||
|
||
```shell | ||
|
||
echo "== start sample_docker" | ||
docker run -d -p 5000:5000 docker_sample & | ||
docker ps | ||
|
||
echo "== wait 3s for startup" | ||
sleep 3s | ||
docker run -d -p 5000:5000 docker_sample | ||
# and the server should start instantly | ||
curl http://localhost:5000 | ||
``` | ||
|
||
echo "== curl both routes" | ||
curl http://localhost:5000 | ||
curl http://localhost:5000/again | ||
## Running unit tests | ||
|
||
``` | ||
```shell | ||
docker build -t docker_sample:test --target base . | ||
docker run --rm docker_sample:test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters