Test 7 #68
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: Deploy to EC2 | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Debug Secret | |
run: | | |
echo "EC2_SSH_KEY is set: ${{ secrets.AWS_INSTANCE_SSH_PRIVATE_KEY != '' }}" | |
echo "KNOWN_HOSTS is set: ${{ secrets.KNOWN_HOSTS != '' }}" | |
echo "AWS_INSTANCE_IP is set: ${{ secrets.AWS_INSTANCE_IP != '' }}" | |
- 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 -o StrictHostKeyChecking=accept-new [email protected] " | |
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 && | |
docker-compose --env-file .env -f infra/docker/docker-compose.yml up -d | |
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'" |