From a4a588be94af0280e4a0ff474734ea245e65cd90 Mon Sep 17 00:00:00 2001 From: gitea Date: Tue, 25 Nov 2025 18:20:52 +0330 Subject: [PATCH] deploying cicd demo app --- .gitea/workflows/cicd.yaml | 46 +++++++++++++++++++++++++++++--------- Dockerfile | 8 +++++++ app.py | 9 ++++++++ requirements.txt | 1 + 4 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 Dockerfile create mode 100644 app.py create mode 100644 requirements.txt diff --git a/.gitea/workflows/cicd.yaml b/.gitea/workflows/cicd.yaml index 52dbb92..3df2d9e 100644 --- a/.gitea/workflows/cicd.yaml +++ b/.gitea/workflows/cicd.yaml @@ -1,20 +1,46 @@ -name: Hello from Gitea Actions +name: Build and Deploy Demo App on: - push: # run on every push + push: branches: - - main # adjust if your default branch is different + - main # Or whichever branch you want to trigger on jobs: - hello: - runs-on: ubuntu-latest # must match your runner's label + build-and-deploy: + runs-on: ubuntu-latest # Use a label that supports Docker; adjust if needed (e.g., cth-ubuntu-latest) + steps: - name: Checkout code uses: actions/checkout@v4 - - name: Say hello - run: | - echo "PayamOps from Gitea Actions!" - echo "Runner: ${{ runner.name }}" - echo "Repo: ${{ gitea.repository }}" + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build Docker image + run: docker build -t demo-app:latest . + + - name: Save Docker image to tar + run: docker save demo-app:latest > demo-app.tar + + - name: Set up SSH + run: | + apt update && apt install -y openssh-client + mkdir -p ~/.ssh + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + eval "$(ssh-agent -s)" + ssh-add ~/.ssh/id_ed25519 + ssh-keyscan -p ${{ secrets.SERVER_PORT }} ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts + + - name: Copy tar to server via SCP + run: scp -o StrictHostKeyChecking=no -P ${{ secrets.SERVER_PORT }} demo-app.tar ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:${{ secrets.DEPLOY_PATH }}demo-app.tar + + - name: Deploy on server via SSH + run: | + ssh -o StrictHostKeyChecking=no -p ${{ secrets.SERVER_PORT }} ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << EOF + docker load -i ${{ secrets.DEPLOY_PATH }}demo-app.tar + docker stop demo-app || true + docker rm demo-app || true + docker run -d --name demo-app -p 5000:5000 --restart unless-stopped demo-app:latest + rm ${{ secrets.DEPLOY_PATH }}demo-app.tar # Clean up + EOF diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..42afe5a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.12-slim + +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY app.py . +EXPOSE 5000 +CMD ["python", "app.py"] diff --git a/app.py b/app.py new file mode 100644 index 0000000..643e1f9 --- /dev/null +++ b/app.py @@ -0,0 +1,9 @@ +from flask import Flask +app = Flask(__name__) + +@app.route('/') +def hello(): + return "

Hello from the Realistic Demo App!

This is a simple Flask server for demonstration.

" + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0647450 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +flask==3.0.3