fix #16
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: Build and Deploy | |
| on: | |
| push: | |
| branches: [ "main" , "staging" ] | |
| jobs: | |
| build-api: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Extract branch name | |
| shell: bash | |
| run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | |
| id: extract_branch | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to TGM Docker Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: registry.tgm.one | |
| username: robot$foligo+github | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Generate API Tag Names | |
| run: | | |
| echo "${{ steps.extract_branch.outputs.branch }}" | |
| if [ ${{ steps.extract_branch.outputs.branch }} = "main" ]; then | |
| echo "TAG_LATEST_API=api:latest" >> $GITHUB_ENV | |
| echo "TAG_COMMIT_API=api:$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
| elif [ ${{ steps.extract_branch.outputs.branch }} = "staging" ]; then | |
| echo "TAG_LATEST_API=api-stage:latest" >> $GITHUB_ENV | |
| echo "TAG_COMMIT_API=api-stage:$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
| else | |
| exit 0 | |
| fi | |
| - name: Build and push API | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./api | |
| platforms: linux/amd64,linux/arm64 | |
| file: ./api/.docker/Dockerfile | |
| push: true | |
| tags: | | |
| registry.tgm.one/foligo/${{ env.TAG_LATEST_API }} | |
| registry.tgm.one/foligo/${{ env.TAG_COMMIT_API }} | |
| cache-from: type=registry,ref=registry.tgm.one/foligo/${{ env.TAG_LATEST_API }} | |
| cache-to: type=inline | |
| build-dashboard: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Extract branch name | |
| shell: bash | |
| run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | |
| id: extract_branch | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to TGM Docker Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: registry.tgm.one | |
| username: robot$foligo+github | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Generate Website Tag Names | |
| run: | | |
| echo "${{ steps.extract_branch.outputs.branch }}" | |
| if [ ${{ steps.extract_branch.outputs.branch }} = "main" ]; then | |
| echo "TAG_LATEST_DASHBOARD=dashboard:latest" >> $GITHUB_ENV | |
| echo "TAG_COMMIT_DASHBOARD=dashboard:$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
| elif [ ${{ steps.extract_branch.outputs.branch }} = "staging" ]; then | |
| echo "TAG_LATEST_DASHBOARD=dashboard-stage:latest" >> $GITHUB_ENV | |
| echo "TAG_COMMIT_DASHBOARD=dashboard-stage:$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
| else | |
| exit 0 | |
| fi | |
| - name: Build and push Dashboard | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./dashboard | |
| platforms: linux/amd64,linux/arm64 | |
| file: ./dashboard/.docker/Dockerfile | |
| push: true | |
| tags: | | |
| registry.tgm.one/foligo/${{ env.TAG_LATEST_DASHBOARD }} | |
| registry.tgm.one/foligo/${{ env.TAG_COMMIT_DASHBOARD }} | |
| cache-from: type=registry,ref=registry.tgm.one/foligo/${{ env.TAG_LATEST_DASHBOARD }} | |
| cache-to: type=inline | |
| build-sites: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Extract branch name | |
| shell: bash | |
| run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | |
| id: extract_branch | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to TGM Docker Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: registry.tgm.one | |
| username: robot$foligo+github | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Generate Sites Tag Names | |
| run: | | |
| echo "${{ steps.extract_branch.outputs.branch }}" | |
| if [ ${{ steps.extract_branch.outputs.branch }} = "main" ]; then | |
| echo "TAG_LATEST_SITES=sites:latest" >> $GITHUB_ENV | |
| echo "TAG_COMMIT_SITES=sites:$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
| elif [ ${{ steps.extract_branch.outputs.branch }} = "staging" ]; then | |
| echo "TAG_LATEST_SITES=sites-stage:latest" >> $GITHUB_ENV | |
| echo "TAG_COMMIT_SITES=sites-stage:$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
| else | |
| exit 0 | |
| fi | |
| - name: Build and push Sites | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./sites | |
| platforms: linux/amd64,linux/arm64 | |
| file: ./sites/.docker/Dockerfile | |
| push: true | |
| tags: | | |
| registry.tgm.one/foligo/${{ env.TAG_LATEST_SITES }} | |
| registry.tgm.one/foligo/${{ env.TAG_COMMIT_SITES }} | |
| cache-from: type=registry,ref=registry.tgm.one/foligo/${{ env.TAG_LATEST_SITES }} | |
| cache-to: type=inline | |
| deploy-rancher: | |
| needs: [build-api, build-dashboard, build-sites] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Extract branch name | |
| shell: bash | |
| run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | |
| id: extract_branch | |
| - name: Redeploy Rancher | |
| run: | | |
| url='https://rancher.tgm.one' | |
| cluster=c-jxhnr | |
| token=${{ secrets.RANCHER_TOKEN }} | |
| redeploy() { | |
| local app=$1 | |
| pod_upgrade_body=$(curl -s -u "$token" \ | |
| -k $url/k8s/clusters/$cluster/v1/apps.deployments/$namespace/$app \ | |
| -X GET \ | |
| -H 'Accept: application/json' \ | |
| -H 'Content-Type: application/json' \ | |
| -H 'Pragma: no-cache' \ | |
| -H 'Cache-Control: no-cache' 2>&1 | sed "s/\"cattle\.io\/timestamp\"\:\"[0-9T:Z-]*\"/\"cattle\.io\/timestamp\":\"$(date -u +"%Y-%m-%dT%H:%M:%SZ")\"/g") | |
| curl -u "$token" \ | |
| -k -s $url/k8s/clusters/$cluster/v1/apps.deployments/$namespace/$app \ | |
| -X PUT \ | |
| -H 'Accept: application/json' \ | |
| -H 'Content-Type: application/json' \ | |
| --data-binary "$pod_upgrade_body" --compressed | |
| } | |
| echo "${{ steps.extract_branch.outputs.branch }}" | |
| if [ ${{ steps.extract_branch.outputs.branch }} = "main" ]; then | |
| namespace=foligo | |
| redeploy "api" | |
| redeploy "dashboard" | |
| redeploy "sites" | |
| elif [ ${{ steps.extract_branch.outputs.branch }} = "staging" ]; then | |
| namespace=foligo-staging | |
| redeploy "api" | |
| redeploy "dashboard" | |
| redeploy "sites" | |
| else | |
| exit 0 | |
| fi |