fix: deploy.yml #89
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 | |
on: | |
push: | |
branches: [ main-banana ] | |
env: | |
SERVER_HOST: ${{ secrets.SERVER_HOST }} | |
SERVER_PORT: ${{ secrets.SERVER_PORT }} | |
SERVER_USER: ${{ secrets.SERVER_USERNAME }} | |
SERVER_PATH: /home | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3.0.0 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image | |
run: | | |
touch .env.prod | |
echo "${{ secrets.ENV }}" > .env.prod | |
docker-compose -f docker-compose.yml build | |
docker-compose -f docker-compose.yml push | |
- name: Deploy to the Server | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_PRIVATE_KEY" > ../private.key | |
sudo chmod 600 ../private.key | |
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts | |
echo "${{ secrets.SSH_PASSPHRASE }}" | ssh-agent bash -c "\ | |
ssh-add ../private.key && \ | |
ssh -o StrictHostKeyChecking=no -tt ${{ env.SERVER_USER }}@${{ env.SERVER_HOST }} -p ${{ env.SERVER_PORT }} '\ | |
{ cd ${{ env.SERVER_PATH }}/teamapp-backend || \ | |
cd ${{ env.SERVER_PATH }} && \ | |
git clone https://github.com/SoftBananas/teamapp-backend.git; } && \ | |
cd teamapp-backend; \ | |
echo \"$ENV\" > .env.prod && \ | |
docker-compose down && \ | |
git pull && \ | |
docker-compose up -d; \ | |
exit'" | |
shell: bash | |
env: | |
ENV: ${{ secrets.ENV }} | |
SSH_PRIVATE_KEY: ${{secrets.SSH_KEY}} | |
SSH_KNOWN_HOSTS: ${{secrets.SSH_KNOWN_HOSTS}} | |
SSH_KEY_PATH: ${{ github.workspace }}/../private.key |