Skip to content

Commit

Permalink
Merge pull request #326 from jdrouet/clean-docker-sample
Browse files Browse the repository at this point in the history
update docker sample by caching dependencies
  • Loading branch information
JohnTitor authored May 28, 2020
2 parents e4b94fc + 1088756 commit 22c8eaa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
23 changes: 16 additions & 7 deletions docker_sample/Dockerfile
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" ]
27 changes: 13 additions & 14 deletions docker_sample/README.MD
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
```
8 changes: 8 additions & 0 deletions docker_sample/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ async fn main() -> std::io::Result<()> {
.run()
.await
}

#[cfg(test)]
mod tests {
#[test]
fn sample_test() {
assert!(true);
}
}

0 comments on commit 22c8eaa

Please sign in to comment.