Updated versions of actions #22
This file contains 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: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "**/*.py" | |
- "pyproject.toml" | |
- "tests/**" | |
- "features/**" | |
- "Dockerfile" | |
- "docker-compose.yml" | |
- "production.env" | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
container: | |
image: python:3.9-slim | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: | | |
apt-get update && apt-get install -y curl && \ | |
curl -sSL https://install.python-poetry.org | python3 - && \ | |
ln -s /github/home/.local/bin/poetry /usr/local/bin/poetry | |
- name: Configure Poetry | |
run: poetry config virtualenvs.create false && poetry install | |
- name: Run tests | |
run: PYTHONPATH=. pytest --cov=echopages -s tests | |
build: | |
runs-on: ubuntu-latest | |
needs: test | |
services: | |
docker: | |
image: docker:19.03.12 | |
options: --privileged | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to Docker Hub | |
run: echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin | |
env: | |
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
DOCKER_HUB_USERNAME: pachovit | |
- name: Build and push Docker image | |
run: | | |
docker build -t pachovit/echopages:latest . | |
docker push pachovit/echopages:latest | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install SSH key | |
uses: webfactory/ssh-agent@v0.9.0 | |
with: | |
ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }} | |
- name: Copy files to server | |
env: | |
DEPLOY_USER: ${{ secrets.DEPLOY_USER }} | |
DEPLOY_SERVER: ${{ secrets.DEPLOY_SERVER }} | |
run: | | |
scp -o StrictHostKeyChecking=no docker-compose.yml $DEPLOY_USER@$DEPLOY_SERVER:/echopages/docker-compose.yml | |
scp -o StrictHostKeyChecking=no production.env $DEPLOY_USER@$DEPLOY_SERVER:/echopages/production.env | |
- name: Deploy to server | |
env: | |
DEPLOY_USER: ${{ secrets.DEPLOY_USER }} | |
DEPLOY_SERVER: ${{ secrets.DEPLOY_SERVER }} | |
POSTMARK_SERVER_API_TOKEN: ${{ secrets.POSTMARK_SERVER_API_TOKEN }} | |
RECIPIENT_EMAIL: ${{ secrets.RECIPIENT_EMAIL }} | |
run: | | |
ssh -o StrictHostKeyChecking=no $DEPLOY_USER@$DEPLOY_SERVER " | |
echo 'POSTMARK_SERVER_API_TOKEN=${{ secrets.POSTMARK_SERVER_API_TOKEN }}' >> /echopages/production.env; | |
echo 'RECIPIENT_EMAIL=${{ secrets.RECIPIENT_EMAIL }}' >> /echopages/production.env; | |
docker pull pachovit/echopages:latest; | |
docker compose -f /echopages/docker-compose.yml --env-file /echopages/production.env up -d; | |
" |