-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (79 loc) · 2.29 KB
/
ci-cd.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
78
79
80
81
82
83
84
name: CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Lint with flake8
run: |
flake8 bot.py
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: |
python -m unittest discover tests/
build:
needs: [lint, test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Docker
run: |
sudo apt-get update
sudo apt-get install docker.io -y
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build and push Docker image
run: |
docker build -t scambot .
docker tag scambot public.ecr.aws/f5k2n2p7/scambot:latest
docker push public.ecr.aws/f5k2n2p7/scambot:latest
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2
env:
HOST: ${{ secrets.EC2_HOST }}
USER: ${{ secrets.EC2_USER }}
KEY: ${{ secrets.EC2_SSH_KEY }}
run: |
mkdir -p ~/.ssh
echo "$KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh -o StrictHostKeyChecking=no ${USER}@${HOST} '
docker stop scambot || true
docker rm scambot || true
docker pull public.ecr.aws/f5k2n2p7/scambot:latest
docker run -d --name scambot public.ecr.aws/f5k2n2p7/scambot:latest
'