Deploy with docker-compose (#1)
Deploy using docker-compose and GitHub Actions. Created a simple get endpoint to check if server is running on / Updated address from 127.0.0.1 to 0.0.0.0
This commit is contained in:
parent
3ad1ad53fc
commit
c1b9273e0c
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@ -0,0 +1,6 @@
|
||||
.github
|
||||
spec
|
||||
http
|
||||
target
|
||||
README.md
|
||||
.gitignore
|
4
.github/workflows/build.yaml
vendored
4
.github/workflows/build.yaml
vendored
@ -1,10 +1,8 @@
|
||||
name: Rust
|
||||
name: Build & test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
16
.github/workflows/deploy.yml
vendored
Normal file
16
.github/workflows/deploy.yml
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
name: Deploy image to Docker Hub and pull it
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
name: Build and run
|
||||
runs-on: self-hosted
|
||||
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v4
|
||||
- name: Run
|
||||
run: docker-compose up -d --build
|
29
Dockerfile
Normal file
29
Dockerfile
Normal file
@ -0,0 +1,29 @@
|
||||
# Creates a new cargo project, copies the Cargo.toml and Cargo.lock files to the new project,
|
||||
# builds the project, and then copies the built binary to a new image.
|
||||
|
||||
FROM rust:1.78 as build
|
||||
LABEL authors="Martin Berg Alstad"
|
||||
|
||||
RUN USER=root cargo new --bin simplify_truths
|
||||
WORKDIR /simplify_truths
|
||||
|
||||
COPY ./Cargo.lock ./Cargo.lock
|
||||
COPY ./Cargo.toml ./Cargo.toml
|
||||
|
||||
# this build step will cache your dependencies
|
||||
RUN cargo build --release
|
||||
RUN rm src/*.rs
|
||||
|
||||
COPY ./src ./src
|
||||
|
||||
RUN rm ./target/release/deps/simplify_truths*
|
||||
RUN cargo build --release
|
||||
|
||||
FROM debian
|
||||
|
||||
# copy the build artifact from the build stage
|
||||
COPY --from=build /simplify_truths/target/release/simplify_truths .
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["./simplify_truths"]
|
9
docker-compose.yaml
Normal file
9
docker-compose.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
version: '3'
|
||||
services:
|
||||
server:
|
||||
restart: always
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "8000:8000"
|
@ -2,7 +2,7 @@ use std::net::SocketAddr;
|
||||
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
use crate::routing::{simplify, table};
|
||||
use crate::routing::{index, simplify, table};
|
||||
|
||||
mod expressions;
|
||||
mod parsing;
|
||||
@ -13,7 +13,7 @@ mod utils;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], config::PORT));
|
||||
let addr = SocketAddr::from(([0, 0, 0, 0], config::PORT));
|
||||
let listener = TcpListener::bind(&addr)
|
||||
.await
|
||||
.unwrap();
|
||||
@ -21,7 +21,8 @@ async fn main() {
|
||||
println!("Listening on: {}", listener.local_addr().unwrap());
|
||||
|
||||
let routes = simplify::router()
|
||||
.merge(table::router());
|
||||
.merge(table::router())
|
||||
.merge(index::router());
|
||||
|
||||
axum::serve(listener, routes).await.unwrap();
|
||||
}
|
||||
|
11
src/routing/index.rs
Normal file
11
src/routing/index.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use axum::Router;
|
||||
use axum::routing::get;
|
||||
|
||||
pub fn router() -> Router {
|
||||
Router::new()
|
||||
.route("/", get(index))
|
||||
}
|
||||
|
||||
async fn index() -> &'static str {
|
||||
"Welcome to the Simplify Truths API!\n"
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
pub(crate) mod simplify;
|
||||
pub(crate) mod table;
|
||||
pub(crate) mod table;
|
||||
pub(crate) mod index;
|
Loading…
x
Reference in New Issue
Block a user