mirror of
https://github.com/actix/examples
synced 2025-01-22 22:05:57 +01:00
update docker sample by caching dependencies
Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
This commit is contained in:
parent
e4b94fc9a5
commit
10887568a0
@ -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
|
EXPOSE 5000
|
||||||
|
|
||||||
ENTRYPOINT ["/docker_sample"]
|
ENTRYPOINT [ "/usr/bin/docker_sample" ]
|
||||||
|
@ -1,23 +1,22 @@
|
|||||||
|
# Docker sample
|
||||||
|
|
||||||
Build image:
|
## Build image
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker build -t docker_sample --force-rm --no-cache -f Dockerfile .
|
docker build -t docker_sample .
|
||||||
```
|
```
|
||||||
|
|
||||||
Run image:
|
## Run built image
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
docker run -d -p 5000:5000 docker_sample
|
||||||
echo "== start sample_docker"
|
# and the server should start instantly
|
||||||
docker run -d -p 5000:5000 docker_sample &
|
curl http://localhost:5000
|
||||||
docker ps
|
```
|
||||||
|
|
||||||
echo "== wait 3s for startup"
|
## Running unit tests
|
||||||
sleep 3s
|
|
||||||
|
|
||||||
echo "== curl both routes"
|
```shell
|
||||||
curl http://localhost:5000
|
docker build -t docker_sample:test --target base .
|
||||||
curl http://localhost:5000/again
|
docker run --rm docker_sample:test
|
||||||
|
```
|
||||||
```
|
|
||||||
|
@ -24,3 +24,11 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn sample_test() {
|
||||||
|
assert!(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user