diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 3a44f74..1ab3a24 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1b60a53 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/calculator.py b/calculator.py deleted file mode 100644 index ea88c0e..0000000 --- a/calculator.py +++ /dev/null @@ -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 - diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..c82b2fd --- /dev/null +++ b/docker-compose.yaml @@ -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 + diff --git a/index.html b/index.html new file mode 100644 index 0000000..84d6c80 --- /dev/null +++ b/index.html @@ -0,0 +1,15 @@ + + + +
+ + +