feat: switch to scratch docker container
This commit is contained in:
@@ -51,10 +51,12 @@ RUN cp /usr/src/oxker/target/$(cat /.platform)/release/oxker /
|
|||||||
|
|
||||||
FROM alpine:latest AS runtime
|
FROM alpine:latest AS runtime
|
||||||
|
|
||||||
|
# Set an ENV that we're running in a container, so that the application can sleep for 250ms at start
|
||||||
|
ENV OXKER_RUNTIME=container
|
||||||
|
|
||||||
# Copy application binary from builder image
|
# Copy application binary from builder image
|
||||||
COPY --from=builder /oxker /usr/local/bin
|
COPY --from=builder /oxker /usr/local/bin
|
||||||
COPY ./containerised/start_oxker.sh ./
|
|
||||||
|
|
||||||
# Run the application
|
# Run the application
|
||||||
# this is used in the application itself, to stop itself show when running from a docker container, so DO NOT EDIT
|
# this is used in the application itself, to stop itself show when running from a docker container, so DO NOT EDIT
|
||||||
ENTRYPOINT [ "./start_oxker.sh"]
|
ENTRYPOINT [ "./app/oxker"]
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
#############
|
#############
|
||||||
## Runtime ##
|
## Runtime ##
|
||||||
#############
|
#############
|
||||||
|
FROM scratch
|
||||||
|
|
||||||
FROM alpine:latest AS runtime
|
# Set env that we're running in a container, so that the application can sleep for 250ms at start
|
||||||
|
ENV OXKER_RUNTIME=container
|
||||||
|
|
||||||
# Copy application binary from builder image
|
# Copy application binary from builder image
|
||||||
COPY ./target/x86_64-unknown-linux-musl/release/oxker /usr/local/bin
|
COPY ./target/x86_64-unknown-linux-musl/release/oxker /app/
|
||||||
COPY ./containerised/start_oxker.sh ./
|
|
||||||
|
|
||||||
# Run the application
|
# Run the application
|
||||||
# this is used in the application itself, to stop itself show when running from a docker container, so DO NOT EDIT
|
# this is used in the application itself, to stop itself show when running from a docker container, so DO NOT EDIT
|
||||||
ENTRYPOINT [ "./start_oxker.sh"]
|
ENTRYPOINT [ "./app/oxker"]
|
||||||
|
|
||||||
|
# Dev build for testing
|
||||||
|
# docker build -t oxker_dev -f Dockerfile . && docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro oxker_dev
|
||||||
|
|
||||||
|
# Dev build one liner, x86 host
|
||||||
|
# docker image prune -a; cargo build --release --target x86_64-unknown-linux-musl && docker build -t oxker_dev -f containerised/Dockerfile_dev . && docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro oxker_dev
|
||||||
|
|
||||||
## One liner to build musl program, build docker image, then execute the image
|
## One liner to build musl program, build docker image, then execute the image
|
||||||
# cargo build --release --target x86_64-unknown-linux-musl && docker build -t oxker_dev -f containerised/Dockerfile . && docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro oxker_dev
|
# cargo build --release --target x86_64-unknown-linux-musl && docker build -t oxker_dev -f containerised/Dockerfile . && docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro oxker_dev
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Without this sleep, the docker image will instantly close
|
|
||||||
# No idea why this is solving my issue, or even where the issue is originally coming from
|
|
||||||
sleep .1
|
|
||||||
|
|
||||||
exec /usr/local/bin/oxker "$@"
|
|
||||||
+13
-10
@@ -54,6 +54,7 @@ pub struct DockerData {
|
|||||||
app_data: Arc<Mutex<AppData>>,
|
app_data: Arc<Mutex<AppData>>,
|
||||||
args: CliArgs,
|
args: CliArgs,
|
||||||
binate: Binate,
|
binate: Binate,
|
||||||
|
containerised: bool,
|
||||||
docker: Arc<Docker>,
|
docker: Arc<Docker>,
|
||||||
gui_state: Arc<Mutex<GuiState>>,
|
gui_state: Arc<Mutex<GuiState>>,
|
||||||
is_running: Arc<AtomicBool>,
|
is_running: Arc<AtomicBool>,
|
||||||
@@ -175,7 +176,7 @@ impl DockerData {
|
|||||||
|
|
||||||
/// Get all current containers, handle into ContainerItem in the app_data struct rather than here
|
/// Get all current containers, handle into ContainerItem in the app_data struct rather than here
|
||||||
/// Just make sure that items sent are guaranteed to have an id
|
/// Just make sure that items sent are guaranteed to have an id
|
||||||
/// Will ignore any container that uses `./start_oxker.sh` as an entry point, unless the `-s` flag is set
|
/// If in a containerised runtime, will ignore any container that uses the q`./app/oxker` as an entry point, unless the `-s` flag is set
|
||||||
pub async fn update_all_containers(&mut self) -> Vec<(bool, ContainerId)> {
|
pub async fn update_all_containers(&mut self) -> Vec<(bool, ContainerId)> {
|
||||||
let containers = self
|
let containers = self
|
||||||
.docker
|
.docker
|
||||||
@@ -190,15 +191,15 @@ impl DockerData {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|f| match f.id {
|
.filter_map(|f| match f.id {
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
if f.command
|
if self.containerised && f.command
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |c| c.starts_with(ENTRY_POINT))
|
.map_or(false, |c| c.starts_with(ENTRY_POINT))
|
||||||
&& self.args.show_self
|
&& self.args.show_self
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(f)
|
Some(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => None,
|
None => None,
|
||||||
})
|
})
|
||||||
@@ -414,6 +415,7 @@ impl DockerData {
|
|||||||
/// Initialise self, and start the message receiving loop
|
/// Initialise self, and start the message receiving loop
|
||||||
pub async fn init(
|
pub async fn init(
|
||||||
app_data: Arc<Mutex<AppData>>,
|
app_data: Arc<Mutex<AppData>>,
|
||||||
|
containerised: bool,
|
||||||
docker: Docker,
|
docker: Docker,
|
||||||
docker_rx: Receiver<DockerMessage>,
|
docker_rx: Receiver<DockerMessage>,
|
||||||
gui_state: Arc<Mutex<GuiState>>,
|
gui_state: Arc<Mutex<GuiState>>,
|
||||||
@@ -423,6 +425,7 @@ impl DockerData {
|
|||||||
if app_data.lock().get_error().is_none() {
|
if app_data.lock().get_error().is_none() {
|
||||||
let mut inner = Self {
|
let mut inner = Self {
|
||||||
app_data,
|
app_data,
|
||||||
|
containerised,
|
||||||
args,
|
args,
|
||||||
binate: Binate::One,
|
binate: Binate::One,
|
||||||
docker: Arc::new(docker),
|
docker: Arc::new(docker),
|
||||||
|
|||||||
+28
-3
@@ -33,16 +33,33 @@ use ui::{create_ui, GuiState, Status};
|
|||||||
|
|
||||||
use crate::docker_data::DockerMessage;
|
use crate::docker_data::DockerMessage;
|
||||||
|
|
||||||
const ENTRY_POINT: &str = "./start_oxker.sh";
|
// this is the entry point when running as a Docker Container, and is used to check if we are running as a Docker Containerq
|
||||||
|
const ENTRY_POINT: &str = "./app/oxker";
|
||||||
|
|
||||||
|
/// Enable tracing, only really used in debug mode, for now
|
||||||
/// write to file if `-g` is set?
|
/// write to file if `-g` is set?
|
||||||
fn setup_tracing() {
|
fn setup_tracing() {
|
||||||
tracing_subscriber::fmt().with_max_level(Level::INFO).init();
|
tracing_subscriber::fmt().with_max_level(Level::INFO).init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An ENV is set in the ./containerised/Dockerfile, if this is ENV found, then sleep for 250ms, else the container, for as yet unknown reasons, will close immediately
|
||||||
|
/// returns a bool, so that the `update_all_containers()` won't bother to check the entry point unless running via a container
|
||||||
|
fn check_if_containerised() -> bool {
|
||||||
|
if std::env::vars()
|
||||||
|
.into_iter()
|
||||||
|
.any(|x| x == ("OXKER_RUNTIME".to_owned(), "container".to_owned()))
|
||||||
|
{
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(250));
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Create docker daemon handler, and only spawn up the docker data handler if a ping returns non-error
|
/// Create docker daemon handler, and only spawn up the docker data handler if a ping returns non-error
|
||||||
async fn docker_init(
|
async fn docker_init(
|
||||||
app_data: &Arc<Mutex<AppData>>,
|
app_data: &Arc<Mutex<AppData>>,
|
||||||
|
containerised: bool,
|
||||||
docker_rx: Receiver<DockerMessage>,
|
docker_rx: Receiver<DockerMessage>,
|
||||||
gui_state: &Arc<Mutex<GuiState>>,
|
gui_state: &Arc<Mutex<GuiState>>,
|
||||||
is_running: &Arc<AtomicBool>,
|
is_running: &Arc<AtomicBool>,
|
||||||
@@ -53,7 +70,12 @@ async fn docker_init(
|
|||||||
let gui_state = Arc::clone(gui_state);
|
let gui_state = Arc::clone(gui_state);
|
||||||
let is_running = Arc::clone(is_running);
|
let is_running = Arc::clone(is_running);
|
||||||
tokio::spawn(DockerData::init(
|
tokio::spawn(DockerData::init(
|
||||||
app_data, docker, docker_rx, gui_state, is_running,
|
app_data,
|
||||||
|
containerised,
|
||||||
|
docker,
|
||||||
|
docker_rx,
|
||||||
|
gui_state,
|
||||||
|
is_running,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
app_data.lock().set_error(AppError::DockerConnect);
|
app_data.lock().set_error(AppError::DockerConnect);
|
||||||
@@ -87,7 +109,10 @@ fn handler_init(
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
let containerised = check_if_containerised();
|
||||||
|
|
||||||
setup_tracing();
|
setup_tracing();
|
||||||
|
|
||||||
let args = CliArgs::new();
|
let args = CliArgs::new();
|
||||||
let app_data = Arc::new(Mutex::new(AppData::default(args)));
|
let app_data = Arc::new(Mutex::new(AppData::default(args)));
|
||||||
let gui_state = Arc::new(Mutex::new(GuiState::default()));
|
let gui_state = Arc::new(Mutex::new(GuiState::default()));
|
||||||
@@ -95,7 +120,7 @@ async fn main() {
|
|||||||
let (docker_sx, docker_rx) = tokio::sync::mpsc::channel(16);
|
let (docker_sx, docker_rx) = tokio::sync::mpsc::channel(16);
|
||||||
let (input_sx, input_rx) = tokio::sync::mpsc::channel(16);
|
let (input_sx, input_rx) = tokio::sync::mpsc::channel(16);
|
||||||
|
|
||||||
docker_init(&app_data, docker_rx, &gui_state, &is_running).await;
|
docker_init(&app_data, containerised, docker_rx, &gui_state, &is_running).await;
|
||||||
|
|
||||||
handler_init(&app_data, &docker_sx, &gui_state, input_rx, &is_running);
|
handler_init(&app_data, &docker_sx, &gui_state, input_rx, &is_running);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user