1
0
mirror of https://github.com/actix/examples synced 2025-06-28 09:50:36 +02:00

Restructure folders (#411)

This commit is contained in:
Daniel T. Rodrigues
2021-02-25 21:57:58 -03:00
committed by GitHub
parent 9db98162b2
commit c3407627d0
334 changed files with 127 additions and 120 deletions

View 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"

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

View 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
```

View 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
}