-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (73 loc) · 2.56 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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: cimg/python:3.9
steps:
- uses: actions/checkout@v4
- name: Configure Poetry
run: poetry config virtualenvs.create false && poetry install
- name: Run tests
run: PYTHONPATH=. poetry run 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;
"