Remove tianji #83
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 and push image | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
jobs: | |
build-binary: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v3 | |
- name: Build | |
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/resume ./src/*.go | |
- name: List files in ./bin directory | |
run: | | |
ls -lhr ./bin | |
- uses: actions/upload-artifact@master | |
with: | |
name: compiled-binary | |
path: ./bin/resume | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
needs: build-binary | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/download-artifact@master | |
with: | |
name: compiled-binary | |
path: ./bin/resume | |
- name: List files in ./bin directory | |
run: | | |
ls -lhr ./bin | |
- name: List files in current directory | |
run: | | |
pwd | |
ls -lhr . | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
push: true | |
tags: rogierlommers/resume:latest | |
pull-and-run-latest: | |
name: "Pull latest image and run" | |
runs-on: ubuntu-latest | |
needs: build-and-push-image | |
steps: | |
# More info: https://github.com/tailscale/github-action | |
- name: Tailscale | |
uses: tailscale/github-action@v2 | |
with: | |
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} | |
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} | |
tags: tag:ci | |
- name: Configure SSH | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_KEY" > ~/.ssh/ssh.key | |
chmod 600 ~/.ssh/ssh.key | |
cat >>~/.ssh/config <<END | |
Host services | |
HostName $(tailscale ip -4 services) | |
User $SSH_USER | |
IdentityFile ~/.ssh/ssh.key | |
StrictHostKeyChecking no | |
Port 22 | |
END | |
env: | |
SSH_USER: ${{ secrets.SSH_USER }} | |
SSH_KEY: ${{ secrets.SSH_KEY }} | |
- name: Run docker-compose commands | |
run: ssh services 'cd /srv/local/services && docker compose kill resume && docker system prune --all --force && docker compose up resume -d' | |
- name: Run tailscale logouut | |
run: sudo tailscale logout |