added caching to newsletter feature #2
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 | |
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 | |
' |