deploying cicd demo app
All checks were successful
Build and Deploy Demo App / build-and-deploy (push) Successful in 1m42s
All checks were successful
Build and Deploy Demo App / build-and-deploy (push) Successful in 1m42s
This commit is contained in:
@@ -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
|
||||
|
||||
8
Dockerfile
Normal file
8
Dockerfile
Normal file
@@ -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"]
|
||||
9
app.py
Normal file
9
app.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from flask import Flask
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def hello():
|
||||
return "<h1>Hello from the Realistic Demo App!</h1><p>This is a simple Flask server for demonstration.</p>"
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000)
|
||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
flask==3.0.3
|
||||
Reference in New Issue
Block a user