feat: docker build
This commit is contained in:
parent
e6c3b4e063
commit
54acb09d0f
1
.dockerignore
Normal file
1
.dockerignore
Normal file
@ -0,0 +1 @@
|
||||
**/target
|
19
.drone.yml
Normal file
19
.drone.yml
Normal file
@ -0,0 +1,19 @@
|
||||
kind: pipeline
|
||||
type: kubernetes
|
||||
name: default
|
||||
|
||||
metadata:
|
||||
namespace: git
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: docker
|
||||
privileged: true
|
||||
environment:
|
||||
TOKEN:
|
||||
from_secret: registry_token
|
||||
commands:
|
||||
- dockerd &
|
||||
- docker login -u registry -p $TOKEN registry.v0l.io
|
||||
- docker buildx build --push -t registry.v0l.io/lnvps-api:latest .
|
||||
- kill $(cat /var/run/docker.pid)
|
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
ARG IMAGE=rust:bookworm
|
||||
|
||||
FROM $IMAGE AS build
|
||||
WORKDIR /app/src
|
||||
COPY . .
|
||||
RUN apt update && apt -y install protobuf-compiler
|
||||
RUN cargo install --path . --root /app/build
|
||||
|
||||
FROM $IMAGE AS runner
|
||||
WORKDIR /app
|
||||
COPY --from=build /app/build .
|
||||
ENTRYPOINT ["./bin/api"]
|
@ -11,11 +11,13 @@ use lnvps::worker::{WorkJob, Worker};
|
||||
use lnvps_db::{LNVpsDb, LNVpsDbMysql};
|
||||
use log::error;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::path::PathBuf;
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Settings {
|
||||
pub listen: Option<String>,
|
||||
pub db: String,
|
||||
pub lnd: LndConfig,
|
||||
pub read_only: bool,
|
||||
@ -32,15 +34,15 @@ pub struct LndConfig {
|
||||
async fn main() -> Result<(), Error> {
|
||||
pretty_env_logger::init();
|
||||
|
||||
let config: Settings = Config::builder()
|
||||
let settings: Settings = Config::builder()
|
||||
.add_source(File::with_name("config.yaml"))
|
||||
.build()?
|
||||
.try_deserialize()?;
|
||||
|
||||
let db = LNVpsDbMysql::new(&config.db).await?;
|
||||
let db = LNVpsDbMysql::new(&settings.db).await?;
|
||||
db.migrate().await?;
|
||||
|
||||
let lnd = connect(config.lnd.url, config.lnd.cert, config.lnd.macaroon).await?;
|
||||
let lnd = connect(settings.lnd.url, settings.lnd.cert, settings.lnd.macaroon).await?;
|
||||
let provisioner = LNVpsProvisioner::new(db.clone(), lnd.clone());
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
@ -50,7 +52,7 @@ async fn main() -> Result<(), Error> {
|
||||
}
|
||||
|
||||
let status = VmStateCache::new();
|
||||
let mut worker = Worker::new(config.read_only, db.clone(), lnd.clone(), status.clone());
|
||||
let mut worker = Worker::new(settings.read_only, db.clone(), lnd.clone(), status.clone());
|
||||
let sender = worker.sender();
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
@ -85,7 +87,16 @@ async fn main() -> Result<(), Error> {
|
||||
|
||||
let db: Box<dyn LNVpsDb> = Box::new(db.clone());
|
||||
let pv: Box<dyn Provisioner> = Box::new(provisioner);
|
||||
if let Err(e) = rocket::build()
|
||||
|
||||
let mut config = rocket::Config::default();
|
||||
let ip: SocketAddr = match &settings.listen {
|
||||
Some(i) => i.parse()?,
|
||||
None => SocketAddr::new(IpAddr::from([0, 0, 0, 0]), 8000),
|
||||
};
|
||||
config.address = ip.ip();
|
||||
config.port = ip.port();
|
||||
|
||||
if let Err(e) = rocket::Rocket::custom(config)
|
||||
.attach(CORS)
|
||||
.manage(db)
|
||||
.manage(pv)
|
||||
|
Loading…
x
Reference in New Issue
Block a user