Deploy API with Docker Swarm (#2) #63
This file contains hidden or 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: Master CI/CD | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| node-version: [18.19.1] | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v1 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: npm install, build, lint and test | |
| run: | | |
| npm install | |
| npm run build --if-present | |
| npm run lint --if-present | |
| npm run test --if-present | |
| env: | |
| CI: true | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check Out Repo | |
| uses: actions/checkout@v2 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v1 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push | |
| id: docker_build | |
| uses: docker/build-push-action@v2 | |
| with: | |
| context: ./ | |
| file: ./Dockerfile | |
| push: true | |
| tags: ecency/hivesigner-api:latest | |
| - name: Image digest | |
| run: echo ${{ steps.docker_build.outputs.digest }} | |
| - name: SSH and deploy API container | |
| uses: appleboy/ssh-action@5711a203b3207eb1c6cebec6ac2152ab210ec3ae | |
| env: | |
| BROADCAST_NETWORK: ${{secrets.BROADCAST_NETWORK}} | |
| BROADCASTER_USERNAME: ${{secrets.BROADCASTER_USERNAME}} | |
| BROADCASTER_POSTING_WIF: ${{secrets.BROADCASTER_POSTING_WIF}} | |
| API_PORT: ${{secrets.API_PORT}} | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| port: ${{ secrets.SSH_PORT }} | |
| envs: BROADCAST_NETWORK,BROADCASTER_USERNAME,BROADCASTER_POSTING_WIF,API_PORT | |
| script: | | |
| cd ~/hsapi | |
| git pull origin main | |
| export API_PORT=$API_PORT | |
| export BROADCAST_NETWORK=$BROADCAST_NETWORK | |
| export BROADCASTER_USERNAME=$BROADCASTER_USERNAME | |
| export BROADCASTER_POSTING_WIF=$BROADCASTER_POSTING_WIF | |
| docker pull ecency/hivesigner-api:latest | |
| docker stack deploy -c docker-compose.yml hivesigner-api |