Implement Automatic EC2 Deployment on Main Branch Updates
SverreNystad opened this issue · comments
The Cogito Backend needs to have a CI/CD pipeline to make sure everything works and to automatically deploy changes. The application is hosted on an AWS EC2 instance and the codebase is stored on GitHub. I want to automate the deployment process so that any new commits pushed to the main branch automatically trigger an update on the EC2 instance.
Acceptance Criteria:
@sandviklee I need you to set secrete EC2_SSH_PRIVATE_KEY
of the SSH key, i also need EC2_HOST
name and EC2_USERNAME
for the CD pipeline
name: Deploy to EC2
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
- name: Deploy to EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USERNAME: ${{ secrets.EC2_USERNAME }}
run: |
ssh -o StrictHostKeyChecking=no $EC2_USERNAME@$EC2_HOST 'bash -s' < ./deploy_to_ec2.sh
This video shows how to create CD:
https://www.youtube.com/watch?v=zCz6xEFqOXE
How to add new Key pairs
https://linux.how2shout.com/add-a-new-key-pair-to-your-exisitng-aws-ec2-instances/
How to connect to instances remotely
https://www.how2shout.com/linux/how-to-ssh-aws-ec2-linux-instances-remotely/
As we dockerize the container the process of automatically updating production on commits on the main branch will be easier #22
For using Portianer we need to things:
- Portainer with HTTPS.
- NGINX proxy manager can do it, and it pretty simple
Portainer.io has an automatic update feature so it can update the server from github repo. It also have good support for stacks of containers making it much easier to connect all the depolyed systems to the backend without using ssh.
This option seems better for security and scalability according Eduard
As the EC2 instance does not have space for portainer or much more any new projects of moderate size. Portainer can not be taken in use. We need to find a way to get more storage.