fix: the docker build

pull/32/head
Miroito 3 years ago
parent e6933079d7
commit bbabb29447

@ -1,4 +1,4 @@
version: '3' version: "3"
services: services:
client: client:
container_name: fast-insiders-client container_name: fast-insiders-client
@ -6,7 +6,7 @@ services:
build: build:
context: . context: .
args: args:
API_URL: http://localhost:8000/v1/ API_URL: http://localhost:8000/
dockerfile: ./client/Dockerfile dockerfile: ./client/Dockerfile
restart: always restart: always
ports: ports:
@ -19,7 +19,7 @@ services:
build: build:
context: . context: .
args: args:
API_URL: http://localhost:8000/v1/ API_URL: http://localhost:8000/
dockerfile: ./server/Dockerfile dockerfile: ./server/Dockerfile
restart: always restart: always
ports: ports:
@ -44,9 +44,7 @@ services:
- MYSQL_DATABASE=fast_insiders - MYSQL_DATABASE=fast_insiders
- MYSQL_USER=fiuser - MYSQL_USER=fiuser
volumes: volumes:
fi-data: fi-data:
driver: local driver: local
db: db:

@ -1,8 +1,8 @@
FROM rust:1.66-slim as build FROM rust:1.66-slim as build
# Install build dependencies # Install build dependencies
RUN apt update \ RUN apt-get update \
&& apt install -y --no-install-recommends lsb-release apt-transport-https \ && apt-get install -y --no-install-recommends lsb-release apt-transport-https \
build-essential curl wget pkg-config libssl-dev build-essential curl wget pkg-config libssl-dev
# Root of the project # Root of the project
@ -21,20 +21,23 @@ RUN rustup default nightly
ARG API_URL ARG API_URL
ENV API_URL=$API_URL ENV API_URL=$API_URL
# go to src dir
WORKDIR /app/server
# Build the final binary # Build the final binary
RUN cargo build --release --bin server RUN cargo build --release
# prepare deployment image # prepare deployment image
FROM debian:stable-slim FROM debian:stable-slim
# For tls to work # For tls to work
RUN apt-get update && apt-get -y install ca-certificates libssl-dev && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get -y --no-install-recommends install ca-certificates libssl-dev && rm -rf /var/lib/apt/lists/*
WORKDIR /app WORKDIR /app
COPY --from=build /app/target/release/server /app/ COPY --from=build /app/target/release/server /app/
ENV ROCKET_ADDRESS=0.0.0.0 ENV HOST=0.0.0.0
CMD ./server CMD ["./server"]

@ -1,7 +1,13 @@
use std::net::SocketAddr;
use serde::Deserialize; use serde::Deserialize;
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
pub struct Env { pub struct Env {
#[serde(default = "host_default")]
pub host: String,
#[serde(default = "port_default")]
pub port: String,
pub mysql_user: String, pub mysql_user: String,
pub mysql_password: String, pub mysql_password: String,
pub mysql_host: String, pub mysql_host: String,
@ -31,6 +37,14 @@ pub struct Env {
pub get_amf_transaction_interval: u64, pub get_amf_transaction_interval: u64,
} }
fn host_default() -> String {
"127.0.0.1".to_string()
}
fn port_default() -> String {
"8000".to_string()
}
fn mysql_port_default() -> String { fn mysql_port_default() -> String {
"3306".to_string() "3306".to_string()
} }
@ -92,6 +106,7 @@ impl Env {
#[derive(Debug)] #[derive(Debug)]
pub struct Config { pub struct Config {
pub server_address: SocketAddr,
pub database_url: String, pub database_url: String,
pub max_connections: u32, pub max_connections: u32,
pub min_connections: u32, pub min_connections: u32,
@ -113,7 +128,12 @@ impl Config {
env.mysql_user, env.mysql_password, env.mysql_host, env.mysql_port, env.mysql_database env.mysql_user, env.mysql_password, env.mysql_host, env.mysql_port, env.mysql_database
); );
let server_address = format!("{}:{}", env.host, env.port)
.parse()
.expect("Could not parse host and port combination into a valid server address");
let mut config = Config { let mut config = Config {
server_address,
database_url, database_url,
max_connections: env.max_connections, max_connections: env.max_connections,
min_connections: env.min_connections, min_connections: env.min_connections,

@ -16,7 +16,7 @@ use axum::{
Router, Router,
}; };
use sea_orm::DatabaseConnection; use sea_orm::DatabaseConnection;
use std::{net::SocketAddr, time::Duration}; use std::time::Duration;
use tokio::signal; use tokio::signal;
use tower_http::{classify::ServerErrorsFailureClass, cors::CorsLayer, trace::TraceLayer}; use tower_http::{classify::ServerErrorsFailureClass, cors::CorsLayer, trace::TraceLayer};
use tracing::{info, info_span, Span}; use tracing::{info, info_span, Span};
@ -136,7 +136,8 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Run tasks // Run tasks
tokio::task::spawn(async move { run_tasks(&shared_state.db).await }); tokio::task::spawn(async move { run_tasks(&shared_state.db).await });
let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); let addr = CONFIG.server_address;
info!("Server will start listening on {}", addr);
axum::Server::bind(&addr) axum::Server::bind(&addr)
.serve(app.into_make_service()) .serve(app.into_make_service())
.with_graceful_shutdown(shutdown_signal()) .with_graceful_shutdown(shutdown_signal())

Loading…
Cancel
Save