Initial docker setup using rust-musl-builder

Not working yet because sqlx 0.3 doesn't have an offline mode
This commit is contained in:
Tyler Hallada 2020-11-08 21:12:28 -05:00
parent 377a260a2f
commit 1a1806ffc3
7 changed files with 38 additions and 15 deletions

View File

@ -1,15 +0,0 @@
# NOTE: For maximum performance, build using a nightly compiler
# If you are using rust stable, remove the "-Zshare-generics=y" below.
[target.x86_64-unknown-linux-gnu]
linker = "/usr/bin/clang"
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"]
[target.x86_64-apple-darwin]
rustflags = ["-Zshare-generics=y"]
# NOTE: you must manually install lld on windows. you can easily do this with the "scoop" package manager:
# `scoop install llvm`
[target.x86_64-pc-windows-msvc]
linker = "lld-link.exe"
rustflags = ["-Clinker=lld", "-Zshare-generics=y"]

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
target

1
Cargo.lock generated
View File

@ -147,6 +147,7 @@ dependencies = [
"listenfd",
"lru",
"mime",
"openssl-probe",
"seahash",
"serde",
"serde_json",

View File

@ -16,6 +16,7 @@ hyper = "0.13"
lazy_static = "1.4"
listenfd = "0.3"
mime = "0.3"
openssl-probe = "0.1"
tokio = { version = "0.2", features = ["macros", "rt-threaded", "sync"] }
sqlx = { version = "0.3", default-features = false, features = [ "runtime-tokio", "macros", "postgres", "chrono", "uuid", "ipnetwork", "json" ] }
warp = { version = "0.2", features = ["compression"] }

22
Dockerfile Normal file
View File

@ -0,0 +1,22 @@
# -*- mode: dockerfile -*-
# You can override this `--build-arg BASE_IMAGE=...` to use different
# version of Rust or OpenSSL.
ARG BASE_IMAGE=ekidd/rust-musl-builder:nightly-2020-10-08
# Our first FROM statement declares the build environment.
FROM ${BASE_IMAGE} AS builder
# Add our source code.
ADD --chown=rust:rust . ./
# Build our application.
RUN cargo build --release
# Now, we need to build our _real_ Docker container, copying in `using-sqlx`.
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder \
/home/rust/src/target/x86_64-unknown-linux-musl/release/bazaar_realm_api \
/usr/local/bin/
CMD /usr/local/bin/bazaar_realm_api

12
docker-compose.yml Normal file
View File

@ -0,0 +1,12 @@
version: "2.0"
services:
app:
build: .
volumes:
- cargo:/home/rust/.cargo
- target:/home/rust/src/target
volumes:
cargo: {}
target: {}

View File

@ -60,6 +60,7 @@ where
#[tokio::main]
async fn main() -> Result<()> {
openssl_probe::init_ssl_cert_env_vars();
dotenv().ok();
let env_log_filter =
env::var("RUST_LOG").unwrap_or_else(|_| "warp=info,bazaar_realm_api=info".to_owned());