Skip to content

Test

Test #76

Workflow file for this run

name: Deploy to EC2
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.AWS_INSTANCE_SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: Deploy to EC2
env:
HOST: ec2-user@${{ secrets.AWS_INSTANCE_IP }}
run: |
ssh -i StrictHostKeyChecking=accept-new ec2-user@${{ secrets.AWS_INSTANCE_IP }} "
# `set -e` stops the execution of the script if a command or pipeline has an error. We need this to make sure
# the GitHub Action reports a failure if something goes wrong.
set -e
# Make sure the latest commit from the main branch is checked out
sudo mkdir -p /opt/albertclo.com
sudo chown -R ec2-user:ec2-user /opt/albertclo.com
cd /opt/albertclo.com
if [ ! -d .git ]; then git clone https://github.com/AlbertClo/albertclo.com.git . ; fi
git config --global --add safe.directory /opt/albertclo.com
git remote set-url origin https://github.com/AlbertClo/albertclo.com.git
git add -A
git reset HEAD --hard
git checkout main
git fetch origin
git reset --hard origin/main
# Run the docker containers
docker-compose --env-file .env -f infra/docker/docker-compose.yml up -d
# Run build commands
docker-compose --env-file .env -f infra/docker/docker-compose.yml exec php composer install
docker-compose --env-file .env -f infra/docker/docker-compose.yml exec php php artisan migrate
echo 'done'"