testing build and deploy
CI/CD / build (push) Failing after 6s
CI/CD / deploy (push) Has been skipped

This commit is contained in:
2026-05-31 14:25:07 +02:00
parent 2224ab723d
commit f1d11085a1
11 changed files with 129 additions and 53 deletions
+35 -13
View File
@@ -1,27 +1,49 @@
name: CI
name: CI/CD
on:
push:
branches: [main]
branches: [main, dev]
pull_request:
branches: [main]
branches: [main, dev]
jobs:
test:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/setup-node@v4
with:
python-version: "3.12"
node-version: 20
- name: Install dependencies
run: pip install -r requirements.txt
run: npm ci
- name: Run tests
run: pytest -v
- name: Build
run: npm run build
deploy:
runs-on: ubuntu-latest
needs: build
if: gitea.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Build & push Docker image
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | \
docker login git.${{ secrets.DOMAIN }} \
-u ${{ secrets.REGISTRY_USER }} --password-stdin
docker build -t git.${{ secrets.DOMAIN }}/${{ secrets.REGISTRY_USER }}/testapp:latest .
docker push git.${{ secrets.DOMAIN }}/${{ secrets.REGISTRY_USER }}/testapp:latest
- name: Deploy to VPS
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ~/programs/testapp
docker compose pull
docker compose up -d --remove-orphans
+12
View File
@@ -0,0 +1,12 @@
# Stage 1 - build the React app
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Stage 2 - serve with nginx
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
-14
View File
@@ -1,14 +0,0 @@
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
+22
View File
@@ -0,0 +1,22 @@
services:
nginx:
build:
context: .
dockerfile: Dockerfile
image: git.ksan.dev/ksan/testapp:latest
container_name: testapp_nginx
networks:
- frontend
labels:
- traefik.enable=true
- traefik.http.routers.testapp-https.rule=Host(`${DOMAIN}`)
- traefik.http.routers.testapp-https.entrypoints=websecure
- traefik.http.routers.testapp-https.tls=true
- traefik.http.routers.testapp-https.tls.certresolver=cloudflare
- traefik.http.services.testapp.loadbalancer.server.port=80
restart: unless-stopped
networks:
frontend:
external: true
+15
View File
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Testapp</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
+18
View File
@@ -0,0 +1,18 @@
{
"name": "testapp",
"version": "1.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@vitejs/plugin-react": "^4.3.1",
"vite": "^5.4.1"
}
}
-1
View File
@@ -1 +0,0 @@
pytest==8.3.5
+10
View File
@@ -0,0 +1,10 @@
function App() {
return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
<h1>Does this work?</h1>
</div>
)
}
export default App
+10
View File
@@ -0,0 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>
)
-25
View File
@@ -1,25 +0,0 @@
import pytest
from calculator import add, subtract, multiply, divide
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
assert add(0, 0) == 0
def test_subtract():
assert subtract(10, 4) == 6
assert subtract(0, 5) == -5
def test_multiply():
assert multiply(3, 4) == 12
assert multiply(-2, 5) == -10
assert multiply(0, 100) == 0
def test_divide():
assert divide(10, 2) == 5
assert divide(7, 2) == 3.5
def test_divide_by_zero():
with pytest.raises(ValueError, match="Cannot divide by zero"):
divide(5, 0)
+7
View File
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
})