logiunb #37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: server-workflow | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
lint: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Install Pylint | |
run: | | |
python -m pip install --upgrade pip | |
pip install pylint | |
- name: Run Pylint on All Files | |
run: | | |
echo "Running Pylint on all Python files..." | |
find . -name "*.py" ! -path "./tests/*" -path "./src/*" -path "./models/*" | xargs pylint || echo "Fix Pylint issues before proceeding." | |
tests: | |
needs: lint | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Set up virtual environment | |
run: python -m venv venv && source venv/bin/activate | |
- name: Run tests | |
run: python run_tests.py | |
docker: | |
needs: tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/my-repo:latest | |
deploy: | |
needs: docker | |
runs-on: ubuntu-latest | |
steps: | |
- name: Write SSH Key | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.SERVER_SSH }}" > ~/.ssh/fiitBM | |
chmod 600 ~/.ssh/fiitBM | |
- name: Connect to Server and Deploy | |
run: | | |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/fiitBM ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF' | |
echo '${{ secrets.DOCKERHUB_PASSWORD }}' | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/my-repo:latest | |
sudo docker stop my-container || true | |
sudo docker rm my-container || true | |
sudo docker run -d --name my-container -p 5000:5000 ${{ secrets.DOCKERHUB_USERNAME }}/my-repo:latest | |
EOF | |