CD-DEV #22
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: CD-DEV | |
on: | |
workflow_run: | |
workflows: ["CI"] | |
types: | |
- completed | |
jobs: | |
deploy: | |
name: Deploy | |
if: github.event.workflow_run.head_branch == 'develop' | |
runs-on: ubuntu-latest | |
environment: Development | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Docker login | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build image | |
run: | | |
cd ./server | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ vars.IMAGE_NAME }}:latest . | |
- name: Push image | |
run: | | |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ vars.IMAGE_NAME }}:latest | |
- name: Setup ssh | |
run: | | |
mkdir -p ~/.ssh | |
printf "%s" "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
- name: SCP core files | |
run: | | |
scp -r docker-compose.yml nginx.conf db-scripts/ .env ${{ vars.SERVER_USER }}@${{ vars.SERVER_IP }}:~/ | |
- name: SSH into server | |
run: | | |
ssh -o StrictHostKeyChecking=no ${{ vars.SERVER_USER }}@${{ vars.SERVER_IP }} 'bash -s' << 'EOF' | |
docker compose down | |
docker compose up --build -d | |
EOF | |