Skip to content

Commit

Permalink
fix(deploy): fix deploy and add ec2 ssh key
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianVegaA committed Mar 24, 2024
1 parent 3a8b32d commit 2336f85
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ on:
branches:
- main

permissions:
id-token: write # This is required for requesting the JWT

jobs:
build_and_deploy:
runs-on: ubuntu-latest
Expand All @@ -31,26 +28,26 @@ jobs:
- name: Install trunk
run: cargo install trunk

- name: Set up Python
uses: actions/setup-python@v5

- name: Install mccli to enable SSH with OIDC authentication
run: pip install mccli

- name: Build the project
run: trunk build --release

- name: Config AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: arn:aws:iam::471112525273:role/github-oidc
aws-region: ${{ secrets.AWS_REGION }}

- name: Deploy to EC2
uses: easingthemes/ssh-deploy@main
env:
PRIVATE_KEY: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
HOST: ${{ secrets.EC2_HOST }}
USER: ${{ secrets.EC2_USER }}
run: |
rsync -avzr -vvv --delete --exclude '.git/' --exclude '.github/' -e "mccli ssh -o StrictHostKeyChecking=no --oidc" ./dist/ $USER@$HOST:~/dist
rm -f private_key.pem
SSH_PRIVATE_KEY: ${ { secrets.EC2_SSH_KEY }}
REMOTE_HOST: ${{ secrets.EC2_HOST }}
REMOTE_USER: ${{ secrets.EC2_USER }}
TARGET: ~/dist
SOURCE: ./dist

- name: Executing remote ssh commands using ssh key
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
sudo chown -R ${{ secrets.EC2_USER }}:www-data /home/${{ secrets.EC2_USER }}/dist
sudo chmod -R 750 /home/${{ secrets.EC2_USER }}/dist
sudo nginx -t
sudo systemctl restart nginx

0 comments on commit 2336f85

Please sign in to comment.