Automatic Deployment

This is how to do automatic deployment using GitHub actions, which can run code after each code push is made. This is similar to Actions on GitHub Pages or Fastpages.

  • A secret will need to be set up from your AWS EC2 PEM file for your SSH key, in the Repository Settings > Secrets create a new secret called SSH_KEY
  • This SSH_KEY should contain encoded output of your AWS PEM base64 -w 0 aws_ssh_key.pem, this encodes the key to use base64 ASCII characters so it is not in plain text. Verbal instruction will be provided to implementor on where to obtain PEM file, this should be considered secret.
  • GitHub Actions can be specified in the .github/workflows directory. In your repository create a file called .github/workflows/deploy_project.yml with the below content (this decodes the base64 key, uses SSH to update deployment project and rebuild docker container).
yml
name:Deploy to Serveron: [push]
jobs:
  AWS-Deploy:
    runs-on: ubuntu-latest
    steps:
      - run: echo $\{\{ secrets.SSH_KEY \}\} | base64 -d > key.pem
      - run: chmod 400 key.pem
      - run: ssh -i key.pem -o StrictHostKeyChecking=no ubuntu@[your server ip/domain name] 'cd ~/your_project; git pull; docker-compose down; docker-compose up -d --build'