1
0
mirror of https://github.com/actix/examples synced 2025-01-22 14:05:55 +01:00

update docker sample by caching dependencies

Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
This commit is contained in:
Jérémie Drouet 2020-05-27 22:01:26 +02:00
parent e4b94fc9a5
commit 10887568a0
3 changed files with 37 additions and 21 deletions

View File

@ -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" ]

View File

@ -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
docker run -d -p 5000:5000 docker_sample
# and the server should start instantly
curl http://localhost:5000
```
echo "== wait 3s for startup"
sleep 3s
## Running unit tests
echo "== curl both routes"
curl http://localhost:5000
curl http://localhost:5000/again
```
```shell
docker build -t docker_sample:test --target base .
docker run --rm docker_sample:test
```

View File

@ -24,3 +24,11 @@ async fn main() -> std::io::Result<()> {
.run()
.await
}
#[cfg(test)]
mod tests {
#[test]
fn sample_test() {
assert!(true);
}
}