8 Commits

Author SHA1 Message Date
5a2da916fa fix(web) fix api/api in enviroment
All checks were successful
Build, Test and Deploy / test-backend (push) Successful in 19s
Build, Test and Deploy / build-and-push (push) Successful in 16s
Build, Test and Deploy / deploy (push) Successful in 5s
2026-01-31 17:51:10 +01:00
82d1cf2c71 feat(web) back-end routing
All checks were successful
Build, Test and Deploy / test-backend (push) Successful in 15s
Build, Test and Deploy / build-and-push (push) Successful in 23s
Build, Test and Deploy / deploy (push) Successful in 4s
2026-01-31 17:46:35 +01:00
85d7315e30 feat(web) back-end routing
All checks were successful
Build, Test and Deploy / test-backend (push) Successful in 15s
Build, Test and Deploy / build-and-push (push) Successful in 26s
Build, Test and Deploy / deploy (push) Successful in 5s
2026-01-31 17:41:47 +01:00
179ba2b85c fix: cicdl.yaml
All checks were successful
Build, Test and Deploy / test-backend (push) Successful in 18s
Build, Test and Deploy / build-and-push (push) Successful in 19s
Build, Test and Deploy / deploy (push) Successful in 18s
2026-01-29 23:09:38 +01:00
ac8135aec8 fix: cicdl.yaml
Some checks failed
Build, Test and Deploy / test-backend (push) Successful in 12s
Build, Test and Deploy / build-and-push (push) Successful in 13s
Build, Test and Deploy / deploy (push) Failing after 3s
2026-01-29 22:28:09 +01:00
74f040fa50 fix: cicdl.yaml
Some checks failed
Build, Test and Deploy / test-backend (push) Successful in 12s
Build, Test and Deploy / build-and-push (push) Successful in 14s
Build, Test and Deploy / deploy (push) Failing after 3s
2026-01-29 22:07:53 +01:00
73fa36f9ec fix: cicdl.yaml
Some checks failed
Build, Test and Deploy / test-backend (push) Successful in 12s
Build, Test and Deploy / build-and-push (push) Successful in 2m46s
Build, Test and Deploy / deploy (push) Failing after 3s
2026-01-29 21:48:32 +01:00
7fafabad42 fix: ubuntu runner
Some checks failed
Build, Test and Deploy / test-backend (push) Successful in 13s
Build, Test and Deploy / build-and-push (push) Failing after 11s
Build, Test and Deploy / deploy (push) Has been skipped
2026-01-29 19:33:57 +01:00
8 changed files with 117 additions and 101 deletions

View File

@@ -2,136 +2,127 @@ name: Build, Test and Deploy
on:
push:
branches:
- main
- int
- dev
branches: [main, int, dev]
concurrency:
group: print-calculator-${{ gitea.ref }}
cancel-in-progress: true
jobs:
test-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
# Evito actions/setup-python (spesso fragile su act_runner)
- name: Install Python deps + run tests
shell: bash
run: |
pip install -r backend/requirements.txt
pip install pytest httpx
- name: Run Backend Tests
run: |
export PYTHONPATH=$PYTHONPATH:$(pwd)/backend
apt-get update
apt-get install -y --no-install-recommends python3 python3-pip
python3 -m pip install --upgrade pip
python3 -m pip install -r backend/requirements.txt
python3 -m pip install pytest httpx
export PYTHONPATH="${PYTHONPATH}:$(pwd)/backend"
pytest backend/tests
build-and-push:
needs: test-backend
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4
- name: Set Environment Variables
- name: Set TAG + OWNER lowercase
shell: bash
run: |
if [[ "${{ gitea.ref }}" == "refs/heads/main" ]]; then
echo "TAG=prod" >> $GITHUB_ENV
echo "TAG=prod" >> "$GITHUB_ENV"
elif [[ "${{ gitea.ref }}" == "refs/heads/int" ]]; then
echo "TAG=int" >> $GITHUB_ENV
echo "TAG=int" >> "$GITHUB_ENV"
else
echo "TAG=dev" >> $GITHUB_ENV
echo "TAG=dev" >> "$GITHUB_ENV"
fi
echo "OWNER_LOWER=$(echo '${{ gitea.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
- name: Ensure docker CLI exists
shell: bash
run: |
if ! command -v docker >/dev/null 2>&1; then
apt-get update
apt-get install -y --no-install-recommends docker.io
fi
docker version
- name: Login to Gitea Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.REGISTRY_URL }}
username: ${{ secrets.GITEA_USER }}
password: ${{ secrets.GITEA_TOKEN }}
shell: bash
run: |
set -euo pipefail
printf '%s' "${{ secrets.REGISTRY_TOKEN }}" | docker login "${{ secrets.REGISTRY_URL }}" \
-u "${{ secrets.REGISTRY_USER }}" --password-stdin
- name: Build and Push Backend
uses: docker/build-push-action@v4
with:
context: ./backend
push: true
tags: ${{ secrets.REGISTRY_URL }}/${{ gitea.repository_owner }}/print-calculator-backend:${{ env.TAG }}
- name: Build & Push Backend
shell: bash
run: |
BACKEND_IMAGE="${{ secrets.REGISTRY_URL }}/${{ env.OWNER_LOWER }}/print-calculator-backend:${{ env.TAG }}"
docker build -t "$BACKEND_IMAGE" ./backend
docker push "$BACKEND_IMAGE"
- name: Build and Push Frontend
uses: docker/build-push-action@v4
with:
context: ./frontend
push: true
tags: ${{ secrets.REGISTRY_URL }}/${{ gitea.repository_owner }}/print-calculator-frontend:${{ env.TAG }}
- name: Build & Push Frontend
shell: bash
run: |
FRONTEND_IMAGE="${{ secrets.REGISTRY_URL }}/${{ env.OWNER_LOWER }}/print-calculator-frontend:${{ env.TAG }}"
docker build -t "$FRONTEND_IMAGE" ./frontend
docker push "$FRONTEND_IMAGE"
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set Deployment Vars
- name: Set ENV
shell: bash
run: |
if [[ "${{ gitea.ref }}" == "refs/heads/main" ]]; then
echo "ENV=prod" >> $GITHUB_ENV
echo "TAG=prod" >> $GITHUB_ENV
echo "ENV=prod" >> "$GITHUB_ENV"
elif [[ "${{ gitea.ref }}" == "refs/heads/int" ]]; then
echo "ENV=int" >> $GITHUB_ENV
echo "TAG=int" >> $GITHUB_ENV
echo "ENV=int" >> "$GITHUB_ENV"
else
echo "ENV=dev" >> $GITHUB_ENV
echo "TAG=dev" >> $GITHUB_ENV
echo "ENV=dev" >> "$GITHUB_ENV"
fi
- name: Create Remote Directory
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: mkdir -p /mnt/user/appdata/print-calculator/${{ env.ENV }}/
- name: Trigger deploy on Unraid (forced command key)
shell: bash
run: |
set -euo pipefail
- name: Copy Compose File to Server
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "docker-compose.deploy.yml"
target: "/mnt/user/appdata/print-calculator/${{ env.ENV }}/"
apt-get update
apt-get install -y --no-install-recommends openssh-client
- name: Copy Env File to Server
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "deploy/envs/${{ env.ENV }}.env"
target: "/mnt/user/appdata/print-calculator/${{ env.ENV }}/.env"
mkdir -p ~/.ssh
chmod 700 ~/.ssh
- name: Execute Remote Deployment
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /mnt/user/appdata/print-calculator/${{ env.ENV }}/
# Rename the copied env file to strictly '.env' so docker compose picks it up automatically
mv ${{ env.ENV }}.env .env
# Login to registry
echo ${{ secrets.GITEA_TOKEN }} | docker login ${{ secrets.REGISTRY_URL }} -u ${{ secrets.GITEA_USER }} --password-stdin
# Pull new images
# We force reading from .env just to be safe, though default behavior does it too.
docker compose --env-file .env -f docker-compose.deploy.yml pull
# Start/Update services
# TAG is inside .env now, so we don't even need to pass it explicitly!
docker compose --env-file .env -f docker-compose.deploy.yml up -d --remove-orphans
# 1) Prende il secret base64 e rimuove spazi/newline/CR
printf '%s' "${{ secrets.SSH_PRIVATE_KEY_B64 }}" | tr -d '\r\n\t ' > /tmp/key.b64
# 2) (debug sicuro) stampa solo la lunghezza della base64
echo "b64_len=$(wc -c < /tmp/key.b64)"
# 3) Decodifica in chiave privata
base64 -d /tmp/key.b64 > ~/.ssh/id_ed25519
# 4) Rimuove eventuali CRLF dentro la chiave (se proviene da Windows)
tr -d '\r' < ~/.ssh/id_ed25519 > ~/.ssh/id_ed25519.clean
mv ~/.ssh/id_ed25519.clean ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
# 5) Validazione: se fallisce qui, la chiave NON è valida/corrotta
ssh-keygen -y -f ~/.ssh/id_ed25519 >/dev/null
# ... (resto del codice uguale)
ssh-keyscan -H "${{ secrets.SERVER_HOST }}" >> ~/.ssh/known_hosts 2>/dev/null
# Aggiungiamo le opzioni di verbosità se dovesse fallire ancora,
# e assicuriamoci che l'input sia pulito
ssh -i ~/.ssh/id_ed25519 -o BatchMode=yes "${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}" "${{ env.ENV }}"

View File

@@ -23,7 +23,7 @@ services:
image: ${REGISTRY_URL}/${REPO_OWNER}/print-calculator-frontend:${TAG}
container_name: print-calculator-frontend-${ENV}
ports:
- "${FRONTEND_PORT}:80"
- "${FRONTEND_PORT}:8008"
depends_on:
- backend
restart: unless-stopped

View File

@@ -39,6 +39,19 @@
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"budgets": [
{
"type": "initial",
@@ -50,8 +63,7 @@
"maximumWarning": "4kB",
"maximumError": "8kB"
}
],
"outputHashing": "all"
]
},
"development": {
"optimization": false,
@@ -59,6 +71,7 @@
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {

View File

@@ -20,6 +20,8 @@ interface QuoteResponse {
};
}
import { environment } from '../../environments/environment';
@Component({
selector: 'app-calculator',
standalone: true,
@@ -61,7 +63,7 @@ export class CalculatorComponent {
this.error = '';
this.results = null;
this.http.post<QuoteResponse>('http://localhost:8000/calculate/stl', formData)
this.http.post<QuoteResponse>(`${environment.apiUrl}/calculate/stl`, formData)
.subscribe({
next: res => {
this.results = res;

View File

@@ -1,13 +1,14 @@
import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from '../environments/environment';
@Injectable({
providedIn: 'root'
})
export class PrintService {
private http = inject(HttpClient);
private apiUrl = 'http://127.0.0.1:8000'; // Should be in environment
private apiUrl = environment.apiUrl;
calculateQuote(file: File, params?: any): Observable<any> {
const formData = new FormData();

View File

@@ -0,0 +1,4 @@
export const environment = {
production: true,
apiUrl: 'https://3d-fab.ch'
};

View File

@@ -0,0 +1,4 @@
export const environment = {
production: false,
apiUrl: 'http://localhost:8000'
};

View File

@@ -2,6 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex, nofollow">
<title>Frontend</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">