From 6d8163f6a65b48a5d6a315fc67b4ba1cd14c774c Mon Sep 17 00:00:00 2001 From: wancat Date: Fri, 21 Jul 2023 11:53:04 +0800 Subject: [PATCH] Add github action --- .github/workflows/ci_cd.yml | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/ci_cd.yml diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml new file mode 100644 index 0000000..d7ac212 --- /dev/null +++ b/.github/workflows/ci_cd.yml @@ -0,0 +1,53 @@ +name: CI/CD Workflow + +on: + push: + branches: + - main + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/linux-odyssey:latest + + deploy: + needs: build-and-push + runs-on: ubuntu-latest + + steps: + - name: Checkout Tailscale Action + uses: actions/checkout@v3 + with: + repository: 'tsujamin/tailscale-github-action' + path: '.github/actions/tailscale' + + - name: Setup Tailscale VPN + uses: ./.github/actions/tailscale + with: + authkey: ${{ secrets.TAILSCALE_AUTH_KEY }} + + - name: SSH into server and update service + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USER }} + script: | + cd ${{ secrets.SERVER_PATH }} + docker compose pull + docker compose up -d