Skip to content

Commit

Permalink
Introduce caching for dockerfile (#10)
Browse files Browse the repository at this point in the history
* Update Dockerfile to optimize layer caching by separate copying of Cargo files and source code

* Update Dockerfile to correct slackwatch binary path

* Update Docker build-push-action to v5 and enable cache in dev-build workflow

* Update Docker build-push-action to v5 and enable cache in dev-build workflow

* Update Docker build-push-action to v5 and enable cache in dev-build workflow

* Update GitHub Actions workflow to use latest checkout and buildx actions, and enhance caching strategy

* Rename GitHub workflow for clarity on dev builds

* Remove unused file, also testing build time from changes

* Update Docker cache settings in GitHub Actions dev-build workflow

* Remove commented out code and clean up main function in main.rs

* Move dioxus-cli installation before copying source files in Dockerfile

* Move dioxus-cli installation before copying source files in Dockerfile

* Enable Docker build caching for Slackwatch workflow
  • Loading branch information
slackspace-io authored Apr 14, 2024
1 parent 3459cf5 commit 5a85953
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 78 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/dev-build.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Push Slackwatch Image
name: Build and Push Dev Branch

on:
push:
Expand All @@ -9,6 +9,7 @@ on:
- 'src/**'
- 'Dockerfile'
- 'assets/**'
- '.github/workflows/dev-build.yaml'

concurrency:
group: "slackwatch"
Expand All @@ -19,18 +20,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
run: docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
push: true
tags: ghcr.io/slackspace-io/slackwatch:dev,ghcr.io/slackspace-io/slackwatch:${{ github.sha }}
cache-from: type=registry,ref=ghcr.io/slackspace-io/slackwatch:build-cache
cache-to: type=registry,ref=ghcr.io/slackspace-io/slackwatch:build-cache,mode=max
2 changes: 2 additions & 0 deletions .github/workflows/slackwatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ jobs:
file: ./Dockerfile
push: true
tags: ghcr.io/slackspace-io/slackwatch:preview,ghcr.io/slackspace-io/slackwatch:${{ github.sha }}
cache-from: type=registry,ref=ghcr.io/slackspace-io/slackwatch:pr-build-cache
cache-to: type=registry,ref=ghcr.io/slackspace-io/slackwatch:pr-build-cache,mode=max
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
FROM rust:1.77.1 as builder
WORKDIR /app
COPY . .
RUN cargo install [email protected]
COPY Cargo.toml Cargo.lock ./
COPY src ./src
RUN dx build --platform fullstack --release

FROM rust:1.77.1
#RUN apt-get update && rm -rf /var/lib/apt/lists/*
#Copy all files from the builder
WORKDIR /app
COPY --from=builder /app/slackwatch /app/slackwatch
COPY --from=builder /app/target/release/slackwatch /app/slackwatch
EXPOSE 8080
CMD ["/app/slackwatch/slackwatch"]
12 changes: 0 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ use dioxus::prelude::*;
use log::info;
use crate::config::Settings;

//#[cfg(feature = "server")]
//use k8s_openapi::merge_strategies::list::set;
//use std::env;
//
mod config;
mod database;
mod gitops;
Expand All @@ -35,22 +31,17 @@ mod site;
#[tokio::main]
async fn main() {
println!("Hello, world!");
//Logging and env variables
env::set_var("RUST_LOG", "info");
env_logger::init();
// dotenv::dotenv().ok();
// Load Configurations
let settings = Settings::new().unwrap_or_else(|err| {
log::error!("Failed to load settings: {}", err);
panic!("Failed to load settings: {}", err);
});
log::info!("Starting up");
log::info!("Loading configuration {:?}", settings);
//create table if not exist
#[cfg(feature = "server")]
use crate::database::client::create_table_if_not_exist;
create_table_if_not_exist().unwrap();
//working tokio stuff
tokio::task::spawn(services::scheduler::run_scheduler(settings.clone()));
let mut config = dioxus::fullstack::Config::new();

Expand All @@ -59,12 +50,9 @@ async fn main() {
config = config.addr(std::net::SocketAddr::from(([0, 0, 0, 0], 8080)));
}

// Launch the app with the custom menu
let site = std::thread::spawn(|| LaunchBuilder::new().with_cfg(config).launch(App));
//let site = std::thread::spawn(|| launch(App));
log::info!("Started logger");
println!("Started print");
//let _ = web::exweb::site();
site.join().unwrap();
}

Expand Down
60 changes: 0 additions & 60 deletions src/oldc.rs

This file was deleted.

0 comments on commit 5a85953

Please sign in to comment.