diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml new file mode 100644 index 0000000..edef09f --- /dev/null +++ b/.forgejo/workflows/deploy.yml @@ -0,0 +1,35 @@ +name: deploy + +on: + push: + branches: + - master + +jobs: + deploy: + runs-on: host + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + registry: git.hydrar.de + username: ${{ secrets.registry_user }} + password: ${{ secrets.registry_password }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: git.hydrar.de/jmarya/me-site:latest diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml deleted file mode 100644 index bc17b6b..0000000 --- a/.gitea/workflows/deploy.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: deploy - -on: - push: - branches: - - master - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Install Docker - run: curl -fsSL https://get.docker.com | sh - - - name: Log in to Docker registry - run: echo "${{ secrets.registry_password }}" | docker login -u "${{ secrets.registry_user }}" --password-stdin git.hydrar.de - - - name: Build and push Docker image - run: | - docker build -t git.hydrar.de/jmarya/me-site:latest -t git.hydrar.de/jmarya/me-site:latest-amd64 . - docker push git.hydrar.de/jmarya/me-site:latest diff --git a/Dockerfile b/Dockerfile index 44fd850..babdf59 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,10 @@ WORKDIR /app RUN cargo build --release -FROM archlinux +FROM debian:buster -RUN pacman -Syu --noconfirm -RUN pacman -S --noconfirm gnupg ca-certificates openssl-1.1 +RUN apt update && apt upgrade -y +RUN apt install -y gnupg ca-certificates openssl COPY --from=builder /app/target/release/me-site /me-site COPY ./rocket.toml /rocket.toml diff --git a/src/pages/bootstrap.rs b/src/pages/bootstrap.rs index b2a45da..4935ae9 100644 --- a/src/pages/bootstrap.rs +++ b/src/pages/bootstrap.rs @@ -11,21 +11,17 @@ async fn download_file(url: &str, file: &str) { #[get("/bootstrap.min.css")] pub async fn bootstrap_css() -> Option { - NamedFile::open("./cache/bootstrap.mi.await.ok()n.css") - .await - .ok() + NamedFile::open("./cache/bootstrap.min.css").await.ok() } #[get("/bootstrap-icons.css")] pub async fn bootstrap_icons() -> Option { - NamedFile::open("./cache/bootstrap-icon.await.ok()s.css") - .await - .ok() + NamedFile::open("./cache/bootstrap-icons.css").await.ok() } #[get("/bootstrap.bundle.min.js")] pub async fn bootstrap_js() -> Option { - NamedFile::open("./cache/bootstrap.b.await.ok()undle.min.js") + NamedFile::open("./cache/bootstrap.bundle.min.js") .await .ok() } diff --git a/src/pages/html.rs b/src/pages/html.rs index fe3b135..7ded392 100644 --- a/src/pages/html.rs +++ b/src/pages/html.rs @@ -1,5 +1,6 @@ use crate::config::Config; use maud::{html, PreEscaped, DOCTYPE}; +use rocket::http::ContentType; use rocket::request::{FromRequest, Outcome, Request}; pub enum RequestClient { @@ -24,7 +25,7 @@ impl<'r> FromRequest<'r> for RequestClient { pub fn is_browser(req: &Request) -> bool { let ua = req .headers() - .get("usesr-agent") + .get("User-Agent") .next() .unwrap() .to_lowercase(); @@ -37,7 +38,7 @@ pub async fn build_site( disable_color: bool, shadow: bool, config: &Config, -) -> String { +) -> (ContentType, String) { let mut c_class = "bg-dark text-white justify-content-center text-center".to_string(); let mut c_style = String::new(); let mut g_style = "a {text-decoration: none; font-weight: bold; color: white}".to_string(); @@ -64,7 +65,10 @@ pub async fn build_site( }; }; - build_site_from_body(title, &body.into_string()) + ( + ContentType::HTML, + build_site_from_body(title, &body.into_string()), + ) } pub fn build_site_from_body(title: &str, body: &str) -> String { diff --git a/src/pages/index.rs b/src/pages/index.rs index a054a9b..cb7e40f 100644 --- a/src/pages/index.rs +++ b/src/pages/index.rs @@ -1,5 +1,6 @@ use crate::config; use maud::{html, PreEscaped}; +use rocket::http::ContentType; use rocket::{form::Form, get, post, response::Redirect, uri, FromForm, State}; use serde::{Deserialize, Serialize}; @@ -19,7 +20,7 @@ pub async fn message_post(msg: Form, config: &State } #[get("/message")] -pub async fn message_page(config: &State) -> String { +pub async fn message_page(config: &State) -> (ContentType, String) { let post_uri = uri!(message_post).to_string(); let resp = html! { @@ -39,7 +40,10 @@ pub async fn message_page(config: &State) -> String { } #[get("/mirrors.txt")] -pub async fn mirrors(r: RequestClient, config: &State) -> Option { +pub async fn mirrors( + r: RequestClient, + config: &State, +) -> Option<(ContentType, String)> { if let Ok(mirror_file) = std::fs::File::open("./config/mirrors.txt") { let content = std::io::read_to_string(mirror_file).ok()?; if matches!(r, RequestClient::Browser) { @@ -53,14 +57,17 @@ pub async fn mirrors(r: RequestClient, config: &State) -> Option return Some(build_site(resp.into_string(), "Mirrors", false, true, config).await); } - return Some(content); + return Some((ContentType::Plain, content)); } None } #[get("/public_key")] -pub async fn public_key(r: RequestClient, config: &State) -> Option { +pub async fn public_key( + r: RequestClient, + config: &State, +) -> Option<(ContentType, String)> { if matches!(r, RequestClient::Browser) { let host = config.base_url(); let key = std::io::read_to_string( @@ -90,7 +97,7 @@ pub async fn public_key(r: RequestClient, config: &State) -> Opt if let Ok(key_f) = std::fs::File::open("./config/pub.key") { if let Ok(key_data) = std::io::read_to_string(key_f) { - return Some(key_data); + return Some((ContentType::Plain, key_data)); } } @@ -160,7 +167,7 @@ fn build_donation_block(conf: &config::Config) -> String { } #[get("/")] -pub async fn index(conf: &State) -> String { +pub async fn index(conf: &State) -> (ContentType, String) { let information_block = build_information_block(conf); let contact_block = build_contact_block(conf); let donation_block = build_donation_block(conf);