generated from alecodes/base-template
Compare commits
2 commits
29756b9578
...
ff1a9858cd
| Author | SHA1 | Date | |
|---|---|---|---|
| ff1a9858cd | |||
| b22a5e5876 |
3 changed files with 79 additions and 8 deletions
62
.forgejo/workflows/build-image.yaml
Normal file
62
.forgejo/workflows/build-image.yaml
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
name: Publish image
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
create-docker-images:
|
||||
runs-on: host
|
||||
steps:
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.alecodes.page
|
||||
username: ${{ vars.CONTAINER_REGISTRY_USER }}
|
||||
password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
outputs: |
|
||||
type=local,dest=./build-out
|
||||
type=docker
|
||||
tags: |
|
||||
git.alecodes.page/alecodes/compendium:latest
|
||||
git.alecodes.page/alecodes/compendium:${{ github.sha }}
|
||||
|
||||
- name: Publish release
|
||||
uses: https://code.forgejo.org/actions/forgejo-release@v2.5.0
|
||||
with:
|
||||
url: "https://git.alecodes.page"
|
||||
repo: "alecodes/compendium"
|
||||
direction: upload
|
||||
# tag: "${{ github.ref_name }}"
|
||||
sha: "${{ github.sha }}"
|
||||
release-dir: build-out
|
||||
# token: ${{ secrets.TOKEN }}
|
||||
override: ${{ vars.OVERRIDE || "false" }}
|
||||
verbose: ${{ vars.VERBOSE || "false" }}
|
||||
|
||||
# deploy:
|
||||
# runs-on: ubuntu-latest
|
||||
# needs:
|
||||
# - create-docker-images
|
||||
# steps:
|
||||
# - name: Checkout code
|
||||
# uses: actions/checkout@v4
|
||||
# - name: 'Docker Stack Deploy'
|
||||
# uses: https://github.com/cssnr/stack-deploy-action@v1
|
||||
# with:
|
||||
# host: ${{ vars.DOCKER_SWARM_HOST }}
|
||||
# port: ${{ vars.DOCKER_SWARM_PORT }}
|
||||
# user: ${{ secrets.DOCKER_SWARM_USER }}
|
||||
# ssh_key: '${{ secrets.DOCKER_SWARM_SSH_KEY }}'
|
||||
# file: 'docker-stack.yaml'
|
||||
# name: 'personal_page'
|
||||
|
|
@ -2,7 +2,7 @@ use std::fmt::Display;
|
|||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::Result;
|
||||
use crate::{Error, Result};
|
||||
use figment::providers::{Env, Format, Serialized, Toml};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
@ -19,7 +19,11 @@ pub struct DBConfig {
|
|||
|
||||
impl Display for DBConfig {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.generate_db_string(true))
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
self.generate_db_string(true).map_err(|_| std::fmt::Error)?
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -36,13 +40,16 @@ impl Default for DBConfig {
|
|||
}
|
||||
|
||||
impl DBConfig {
|
||||
pub fn generate_db_string(&self, ofuscate: bool) -> String {
|
||||
pub fn generate_db_string(&self, ofuscate: bool) -> Result<String> {
|
||||
if let Some(value) = &self.string {
|
||||
return value.clone();
|
||||
return Ok(value.clone());
|
||||
}
|
||||
|
||||
let db_password = if ofuscate {
|
||||
let mut db_password = self.password.clone().unwrap();
|
||||
let mut db_password = self
|
||||
.password
|
||||
.clone()
|
||||
.ok_or(Error::Runtime("No database password provided"))?;
|
||||
let password_length = db_password.len();
|
||||
|
||||
let visible_characters = 4;
|
||||
|
|
@ -59,7 +66,9 @@ impl DBConfig {
|
|||
|
||||
db_password
|
||||
} else {
|
||||
self.password.clone().unwrap()
|
||||
self.password
|
||||
.clone()
|
||||
.ok_or(Error::Runtime("No database password provided"))?
|
||||
};
|
||||
|
||||
let db_string = format!(
|
||||
|
|
@ -67,7 +76,7 @@ impl DBConfig {
|
|||
self.user, db_password, self.host, self.name,
|
||||
);
|
||||
|
||||
db_string.to_owned()
|
||||
Ok(db_string.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ async fn main() -> Result<()> {
|
|||
|
||||
let pool = PgPoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect(&config.db.generate_db_string(false))
|
||||
.connect(&config.db.generate_db_string(false)?)
|
||||
.await?;
|
||||
|
||||
let (tx_state, tx_layer) = Tx::setup(pool);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue