From 56b546314276338d4dcafd89de063093d0b31172 Mon Sep 17 00:00:00 2001 From: darkicewolf50 Date: Thu, 22 May 2025 16:01:55 -0600 Subject: [PATCH] feat(docker): dockerized and added auto upload actions --- .gitea/workflows/Actions.yml | 45 ++++++++++++++++++++++++++++++++++++ README.md | 8 ++++++- docker-compose.yaml | 11 +++++++++ dockerfile | 24 +++++++++++++++++++ src/lib.rs | 8 +++---- 5 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 .gitea/workflows/Actions.yml create mode 100644 docker-compose.yaml create mode 100644 dockerfile diff --git a/.gitea/workflows/Actions.yml b/.gitea/workflows/Actions.yml new file mode 100644 index 0000000..fc3d2e4 --- /dev/null +++ b/.gitea/workflows/Actions.yml @@ -0,0 +1,45 @@ +# name of the workflow. +# this is optional. +name: Cloud Actions + +# events that will trigger this workflow. +# here, we only have "pull_request", so the workflow will run +# whenever we create a pull request. +# other examples: [push] and [pull_request, push] +on: + pull_request: + + push: + branches: + - master + +# each workflow must have at least one job. +# jobs run in parallel by default (we can change that). +# each job groups together a series of steps to accomplish a purpose. +jobs: + Dockerhub: + runs-on: ubuntu-latest + # if: ${{ github.ref == 'refs/heads/master' || github.event.pull_request.merged == true }} # Runs if it's a push to 'main' or a merged PR to 'main' + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: Login to Dockerhub # log into docker hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} # Using secret for Docker username + password: ${{ secrets.DOCKER_PASSWORD }} # Using secret for Docker password + id: docker-login + + - name: build container image # build the container + run: docker compose build --no-cache + id: docker-build + + - name: Upload to Dockerhub + run: docker push darkicewolf50/darkicewolf50cloud:latest + if: ${{ steps.docker-login.outcome == 'success' && steps.docker-build.outcome == 'success' }} + + - name: Upload with Git SHA tag + run: | + docker tag darkicewolf50/darkicewolf50cloud:latest darkicewolf50/darkicewolf50cloud:${{ github.sha }} + docker push darkicewolf50/darkicewolf50cloud:${{ github.sha }} diff --git a/README.md b/README.md index 13fc59e..0dcbdd4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # darkicewolf50Cloud -My backend application, self-hosted and primarily written in Rust \ No newline at end of file +My backend application, self-hosted and primarily written in Rust + +This is a mirror of the repo, live code is hosted [here](https://gitea.bajacloud.duckdns.org/darkicewolf50/darkicewolf50Cloud) as well as any testing of the code. + +I do not consent for this code to be used in any training data for AI or AI like products or services. + +This is only uploaded here so that I can bet those sweet sweet green marks on my gituhb profile. diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..fd32182 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,11 @@ +services: + bajacloud: + container_name: darkicewolf50cloud + image: darkicewolf50/darkicewolf50cloud:latest + # restart: unless-stopped + build: . # do not include in delpoyment version + ports: + - 5050:8000 + volumes: + - ./database:/database + - ./blogs:/blogs diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..778af72 --- /dev/null +++ b/dockerfile @@ -0,0 +1,24 @@ +# ----------- Build Stage ----------- +FROM rust:1.87-slim AS builder + +WORKDIR /darkicewolf50_cloud + +# Install build dependencies +RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/* + +# Copy source and build +COPY . . +RUN cargo build --release + +# ----------- Runtime Stage ----------- +FROM debian:bookworm-slim + +# Install runtime dependencies (e.g., for OpenSSL if needed) +RUN apt-get update && apt-get install -y libssl-dev ca-certificates && rm -rf /var/lib/apt/lists/* + +WORKDIR /darkicewolf50_cloud +COPY --from=builder /darkicewolf50_cloud/target/release/darkicewolf50_cloud . + +EXPOSE 8000 +CMD ["./darkicewolf50_cloud"] + \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 0b2d8e1..78f4b41 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,7 @@ struct TechDes { #[get("/skills")] pub async fn skills_home(req: HttpRequest) -> impl Responder { log_incoming(req, "GET", "/skills"); - let raw_yaml: String = fs::read_to_string("./data_txt/skill_level.yaml").unwrap(); + let raw_yaml: String = fs::read_to_string("/database/skill_level.yaml").unwrap(); // .expect("Cannot open file or missing file."); let vec_yaml = yaml_rust2::YamlLoader::load_from_str(&raw_yaml).unwrap()[0].clone(); @@ -82,7 +82,7 @@ pub async fn project(limit: web::Path, req: HttpRequest) -> impl Responde let limit = limit.into_inner(); - let raw_yaml: String = fs::read_to_string("./data_txt/projects.yaml").unwrap(); + let raw_yaml: String = fs::read_to_string("/database/projects.yaml").unwrap(); let vec_yaml = yaml_rust2::YamlLoader::load_from_str(&raw_yaml).unwrap()[0].clone(); let raw_vec: Vec = vec_yaml @@ -130,7 +130,7 @@ pub async fn get_blog( ) -> impl Responder { log_incoming(req, "GET", "/blogs/blog/{blog_name}"); let blog_name = blog_name.into_inner(); - let file_path = format!("./data_txt/blogs/{blog_name}.md"); + let file_path = format!("/blogs/{}.md", blog_name); let path = Path::new(&file_path); let Ok(blog_text) = fs::read_to_string(&path) else { @@ -180,7 +180,7 @@ pub async fn get_blogs_preview(props: web::Path<(u8, u32)>, req: HttpRequest) -> let (num_limit, page_num) = props.into_inner(); let mut available_blogs: Vec = Vec::new(); - let dir = Path::new("./data_txt/blogs"); + let dir = Path::new("/blogs"); if dir.is_dir() { for entry in fs::read_dir(dir).unwrap() { let entry = entry