question: support uploading images (#53) #149
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: Set up Go 1.20 | |
uses: actions/setup-go@v1 | |
with: | |
go-version: 1.20 | |
id: go | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v3 | |
- name: Get dependencies | |
run: | | |
go mod tidy | |
- name: Build | |
run: | | |
CGO_ENABLED=0 go build -v -ldflags "-w -s -extldflags '-static' -X 'github.com/NekoWheel/NekoBox/internal/conf.BuildCommit=$GITHUB_SHA'" -o NekoBox ./cmd/ | |
- 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: wuhan005/publish-docker-action@master | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
registry: ${{ secrets.DOCKER_REGISTRY }} | |
repository: ${{ secrets.DOCKER_NAME }} | |
auto_tag: true | |
tag_format: ${{ steps.image-tag.outputs.tag }} | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
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 |