|
| 1 | +name: Deploy to Batman Server |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + deploy: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout code (for access to docker-compose-reverseproxy.yaml and nginx.conf) |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Connect to Tailscale |
| 16 | + uses: tailscale/github-action@v2 |
| 17 | + with: |
| 18 | + oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} |
| 19 | + oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} |
| 20 | + tags: tag:batman-ci |
| 21 | + |
| 22 | + - name: Copy nginx.conf to Batman Server |
| 23 | + uses: appleboy/scp-action@v0.1.7 |
| 24 | + with: |
| 25 | + source: "docker-compose-reverseproxy.yaml,nginx.conf" |
| 26 | + target: /home/${{ secrets.BATMAN_SERVER_USER}}/ |
| 27 | + host: ${{ secrets.BATMAN_SERVER_IP }} |
| 28 | + username: ${{ secrets.BATMAN_SERVER_USER }} |
| 29 | + key: ${{ secrets.BATMAN_SERVER_SSH_KEY }} |
| 30 | + |
| 31 | + - name: Deploy to Batman Server |
| 32 | + uses: appleboy/ssh-action@v0.1.0 |
| 33 | + with: |
| 34 | + host: ${{ secrets.BATMAN_SERVER_IP }} |
| 35 | + username: ${{ secrets.BATMAN_SERVER_USER }} |
| 36 | + key: ${{ secrets.BATMAN_SERVER_SSH_KEY }} |
| 37 | + port: 22 |
| 38 | + script: | |
| 39 | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
| 40 | + docker compose -f docker-compose-reverseproxy.yaml up -d |
| 41 | +
|
| 42 | + - name: List and remove non-latest images in Batman Server |
| 43 | + uses: appleboy/ssh-action@v0.1.0 |
| 44 | + with: |
| 45 | + host: ${{ secrets.BATMAN_SERVER_IP }} |
| 46 | + username: ${{ secrets.BATMAN_SERVER_USER }} |
| 47 | + key: ${{ secrets.BATMAN_SERVER_SSH_KEY }} |
| 48 | + port: 22 |
| 49 | + script: | |
| 50 | + images=$(docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep -v ':latest') |
| 51 | + echo "Images to be removed:" |
| 52 | + echo "$images" |
| 53 | +
|
| 54 | + while IFS= read -r image; do |
| 55 | + repo_tag=$(echo $image | awk '{print $1}') |
| 56 | + image_id=$(echo $image | awk '{print $2}') |
| 57 | + echo "Removing image $repo_tag with ID $image_id" |
| 58 | + docker rmi "$image_id" || true |
| 59 | + done <<< "$images" |
0 commit comments