|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + deploy: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + timeout-minutes: 60 |
| 11 | + steps: |
| 12 | + - name: Checkout code |
| 13 | + uses: actions/checkout@v3 |
| 14 | + |
| 15 | + - name: Deploy to server and build |
| 16 | + uses: appleboy/ssh-action@master |
| 17 | + with: |
| 18 | + host: ${{ secrets.SSH_HOST }} |
| 19 | + username: ${{ secrets.SSH_USER }} |
| 20 | + password: ${{ secrets.SSH_PASSWORD }} |
| 21 | + command_timeout: "30m" |
| 22 | + script: | |
| 23 | + mkdir -p ~/frege-app |
| 24 | + |
| 25 | + rm -rf ~/frege-app/repo |
| 26 | + mkdir -p ~/frege-app/repo |
| 27 | + |
| 28 | + cat > ~/frege-app/.env << EOL |
| 29 | + GITLAB_TOKEN=${{ secrets.GITLAB_TOKEN }} |
| 30 | + EOL |
| 31 | +
|
| 32 | + - name: Copy repository to server |
| 33 | + uses: appleboy/scp-action@master |
| 34 | + with: |
| 35 | + host: ${{ secrets.SSH_HOST }} |
| 36 | + username: ${{ secrets.SSH_USER }} |
| 37 | + password: ${{ secrets.SSH_PASSWORD }} |
| 38 | + source: "./" |
| 39 | + target: "~/frege-app/repo" |
| 40 | + rm: false |
| 41 | + strip_components: 0 |
| 42 | + |
| 43 | + - name: Build and run on server |
| 44 | + uses: appleboy/ssh-action@master |
| 45 | + with: |
| 46 | + host: ${{ secrets.SSH_HOST }} |
| 47 | + username: ${{ secrets.SSH_USER }} |
| 48 | + password: ${{ secrets.SSH_PASSWORD }} |
| 49 | + command_timeout: "45m" |
| 50 | + script: | |
| 51 | + cd ~/frege-app/repo |
| 52 | + |
| 53 | + cp .env.template .env |
| 54 | + |
| 55 | + docker compose --profile prod down |
| 56 | + docker compose --profile prod up --build -d |
| 57 | + |
| 58 | + docker compose --profile prod ps |
| 59 | + |
| 60 | + echo "Container logs (last 50 lines):" |
| 61 | + docker compose --profile prod logs --tail=50 |
| 62 | + |
| 63 | + if [ $(docker compose --profile prod ps --status running | grep -v "NAME" | wc -l) -lt 1 ]; then |
| 64 | + echo "Warning: Not all containers are running, but proceeding with deployment." |
| 65 | + else |
| 66 | + echo "All containers started successfully." |
| 67 | + fi |
| 68 | + |
| 69 | + echo "Deployment completed" |
0 commit comments