ci: prevent auto deploy #199
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: Build & Deploy | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
build: | |
name: Build Binary | |
runs-on: ubuntu-latest | |
outputs: | |
image_tag: ${{ steps.image-tag.outputs.tag }} | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v3 | |
- name: Set image tag | |
id: image-tag | |
run: echo "tag=$(date -u '+%Y%m%d-%I%M%S')" >> $GITHUB_OUTPUT | |
- name: Build & Publish to Registry | |
uses: jerray/publish-docker-action@master | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
registry: ${{ secrets.DOCKER_REGISTRY }} | |
repository: ${{ secrets.DOCKER_NAME }} | |
build_args: GITHUB_SHA=${{ github.sha }} | |
tags: ${{ steps.image-tag.outputs.tag }} | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
environment: Production | |
needs: build | |
steps: | |
- name: Deploy to server | |
uses: cross-the-world/ssh-pipeline@master | |
env: | |
DOCKER_NAME: ${{ secrets.DOCKER_NAME }} | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }} | |
DOCKER_TAG: ${{ needs.build.outputs.image_tag }} | |
with: | |
host: ${{ secrets.SSH_IP }} | |
user: ${{ secrets.SSH_NAME }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ secrets.SSH_PORT }} | |
connect_timeout: 10s | |
script: | | |
docker pull $DOCKER_NAME:$DOCKER_TAG | |
docker service update --image $DOCKER_NAME:$DOCKER_TAG nekobox_app | |
docker image prune -a -f |