Merge pull request #9 from johanesPao/dev #3
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: Surreal Ocean ReDeployment to AWS | |
on: | |
# Workflow di-trigger saat push ke branch main | |
# dan terdapat perubahan pada api/ saja | |
# atau perubahan pada file workflow ini sendiri | |
push: | |
branches: | |
- main | |
jobs: | |
deploy-api-surreal-ocean: | |
runs-on: ubuntu-latest | |
environment: aws_deployment | |
env: | |
AWS_DOMAIN: ${{secrets.AWS_DOMAIN}} | |
AWS_USER: ${{secrets.AWS_USER}} | |
AWS_B64_ENCODED_KEY: ${{secrets.AWS_B64_ENCODED_KEY}} | |
AWS_KEY_FILE: ${{secrets.AWS_KEY_FILE}} | |
# PRODUCTION_API_SERVICE: ${{secrets.PRODUCTION_API_SERVICE}} | |
steps: | |
- name: Menuliskan known_hosts pada workflow | |
run: | | |
mkdir -p ~/.ssh | |
touch ~/.ssh/known_hosts | |
ssh-keygen -R $AWS_DOMAIN | |
ssh-keyscan -H $AWS_DOMAIN >> ~/.ssh/known_hosts | |
- name: Menuliskan file private key | |
run: | | |
echo "$AWS_B64_ENCODED_KEY" | base64 --decode > $AWS_KEY_FILE | |
chmod 600 $AWS_KEY_FILE | |
- name: Rebuild dan deploy ulang Surreal Ocean dengan latest tag | |
run: | | |
ssh -i $AWS_KEY_FILE $AWS_USER@$AWS_DOMAIN 'sudo docker compose down && sudo docker image prune -a -f && sudo docker compose up -d' |