|
| 1 | +name: Build and Deploy Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - docker |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v3 |
| 14 | + |
| 15 | + - name: Setup Node and NPM |
| 16 | + uses: actions/setup-node@v3 |
| 17 | + with: |
| 18 | + node-version: 18.14.0 |
| 19 | + |
| 20 | + - name: Install Client NPM Packages |
| 21 | + run: npm ci |
| 22 | + working-directory: client |
| 23 | + |
| 24 | + - name: Compile Client |
| 25 | + run: npm run production |
| 26 | + working-directory: client |
| 27 | + |
| 28 | + - name: Install WSS NPM Packages |
| 29 | + run: npm ci |
| 30 | + working-directory: wss |
| 31 | + |
| 32 | + - name: Compile WSS |
| 33 | + run: npm run production |
| 34 | + working-directory: wss |
| 35 | + |
| 36 | + - name: Build HTTP Docker Image |
| 37 | + run: docker build -f Dockerfile.http -t codewithkyle/tabletopper-http:prod . |
| 38 | + |
| 39 | + - name: Save HTTP Docker Image as Tarball |
| 40 | + run: docker save -o tabletopper-http.tar codewithkyle/tabletopper-http:prod |
| 41 | + |
| 42 | + - name: Build WSS Docker Image |
| 43 | + run: docker build -f Dockerfile.wss -t codewithkyle/tabletopper-wss:prod . |
| 44 | + |
| 45 | + - name: Save WSS Docker Image as Tarball |
| 46 | + run: docker save -o tabletopper-wss.tar codewithkyle/tabletopper-wss:prod |
| 47 | + |
| 48 | + - name: Load SSH Key |
| 49 | + uses: webfactory/[email protected] |
| 50 | + with: |
| 51 | + ssh-private-key: ${{ secrets.SSH_KEY }} |
| 52 | + |
| 53 | + - name: Deploy |
| 54 | + run: scp -o StrictHostKeyChecking=no ./tabletopper-http.tar ./tabletoper-wss.tar ${{ secrets.USERNAME }}@${{ secrets.HOST }}:~/ |
| 55 | + |
| 56 | + - name: Post Deployment |
| 57 | + uses: appleboy/ssh-action@master |
| 58 | + with: |
| 59 | + host: ${{ secrets.HOST }} |
| 60 | + USERNAME: ${{ secrets.USERNAME }} |
| 61 | + PORT: 22 |
| 62 | + KEY: ${{ secrets.SSH_KEY }} |
| 63 | + script: docker load -i ~/tabletopper-wss.tar && docker load -i ~/tabletopper-http.tar |
| 64 | + |
| 65 | + - name: Purge cache |
| 66 | + uses: nathanvaughn/actions-cloudflare-purge@master |
| 67 | + if: success() |
| 68 | + with: |
| 69 | + cf_zone: ${{ secrets.CLOUDFLARE_ZONE }} |
| 70 | + cf_auth: ${{ secrets.CLOUDFLARE_AUTH_KEY }} |
| 71 | + |
0 commit comments