mirror of
https://github.com/actix/examples
synced 2025-06-28 09:50:36 +02:00
Restructure folders (#411)
This commit is contained in:
committed by
GitHub
parent
9db98162b2
commit
c3407627d0
8
basics/docker_sample/Cargo.toml
Normal file
8
basics/docker_sample/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "docker_sample"
|
||||
version = "0.1.0"
|
||||
authors = ["docker_sample <docker_sample@sample.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "3"
|
24
basics/docker_sample/Dockerfile
Normal file
24
basics/docker_sample/Dockerfile
Normal file
@ -0,0 +1,24 @@
|
||||
FROM rust:1-slim-buster AS base
|
||||
|
||||
ENV USER=root
|
||||
|
||||
WORKDIR /code
|
||||
RUN cargo init
|
||||
COPY Cargo.toml /code/Cargo.toml
|
||||
RUN cargo fetch
|
||||
|
||||
COPY src /code/src
|
||||
|
||||
CMD [ "cargo", "test", "--offline" ]
|
||||
|
||||
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 [ "/usr/bin/docker_sample" ]
|
22
basics/docker_sample/README.MD
Normal file
22
basics/docker_sample/README.MD
Normal file
@ -0,0 +1,22 @@
|
||||
# Docker sample
|
||||
|
||||
## Build image
|
||||
|
||||
```shell
|
||||
docker build -t docker_sample .
|
||||
```
|
||||
|
||||
## Run built image
|
||||
|
||||
```shell
|
||||
docker run -d -p 5000:5000 docker_sample
|
||||
# and the server should start instantly
|
||||
curl http://localhost:5000
|
||||
```
|
||||
|
||||
## Running unit tests
|
||||
|
||||
```shell
|
||||
docker build -t docker_sample:test --target base .
|
||||
docker run --rm docker_sample:test
|
||||
```
|
26
basics/docker_sample/src/main.rs
Normal file
26
basics/docker_sample/src/main.rs
Normal file
@ -0,0 +1,26 @@
|
||||
#[macro_use]
|
||||
extern crate actix_web;
|
||||
|
||||
use actix_web::{App, HttpResponse, HttpServer, Responder};
|
||||
|
||||
#[get("/")]
|
||||
async fn index() -> impl Responder {
|
||||
println!("GET: /");
|
||||
HttpResponse::Ok().body("Hello world!")
|
||||
}
|
||||
|
||||
#[get("/again")]
|
||||
async fn again() -> impl Responder {
|
||||
println!("GET: /again");
|
||||
HttpResponse::Ok().body("Hello world again!")
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
println!("Starting actix-web server");
|
||||
|
||||
HttpServer::new(|| App::new().service(index).service(again))
|
||||
.bind("0.0.0.0:5000")?
|
||||
.run()
|
||||
.await
|
||||
}
|
Reference in New Issue
Block a user