Parcourir la source

replace build workflow to use github packages

Aneurin Barker Snook il y a 11 mois
Parent
commit
d18029e291
3 fichiers modifiés avec 19 ajouts et 116 suppressions
  1. 0 23
      .deploy/start.sh.template
  2. 19 22
      .github/workflows/build.yml
  3. 0 71
      .github/workflows/deploy.yml

+ 0 - 23
.deploy/start.sh.template

@@ -1,23 +0,0 @@
-#!/bin/bash
-set -ex
-
-# Pull latest image
-docker pull ${SERVICE_IMAGE}
-
-# Stop and remove running container
-CONTAINERS=$(docker ps --format '{{.Names}}' | awk "/^(${SERVICE_CONTAINER})$/")
-if [ ! -z "£{CONTAINERS}" ]; then
-  echo "£{CONTAINERS}" | xargs docker stop
-  echo "£{CONTAINERS}" | xargs docker rm
-fi
-
-# Start ArangoDB container
-docker run -d -ti --restart unless-stopped --network ${NETWORK} \
-  -v ${SERVICE_CONTAINER}-data:/var/lib/arangodb3 \
-  --env "CSV=${CSV}" \
-  --env "LETSENCRYPT_HOST=${SERVICE_HOST}" \
-  --env "NETWORK_ACCESS=${SERVICE_NETWORK_ACCESS}" \
-  --env "VIRTUAL_HOST=${SERVICE_HOST}" \
-  --env "VIRTUAL_PORT=3000" \
-  --expose "3000" \
-  --name ${SERVICE_CONTAINER} ${SERVICE_IMAGE}

+ 19 - 22
.github/workflows/build.yml

@@ -2,23 +2,15 @@
 #
 #
 # https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#publishing-a-package-using-an-action
 # https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#publishing-a-package-using-an-action
 
 
-name: Build and publish
-
-concurrency:
-  group: build-${{ github.ref }}
-  cancel-in-progress: true
+name: Build Docker image
 
 
 on:
 on:
   workflow_dispatch:
   workflow_dispatch:
   push:
   push:
     branches:
     branches:
       - develop
       - develop
-    paths:
-      - .github/workflows/build.yml
-      - Dockerfile
-      - go.mod
-      - go.sum
-      - main.go
+    tags:
+      - v*
 
 
 env:
 env:
   IMAGE_NAME: ${{ github.repository }}
   IMAGE_NAME: ${{ github.repository }}
@@ -28,6 +20,9 @@ jobs:
   build:
   build:
     name: Build and publish
     name: Build and publish
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
+    permissions:
+      contents: read
+      packages: write
     steps:
     steps:
       - name: Checkout repository
       - name: Checkout repository
         uses: actions/checkout@v4
         uses: actions/checkout@v4
@@ -52,16 +47,18 @@ jobs:
           push: true
           push: true
           tags: ${{ steps.meta.outputs.tags }}
           tags: ${{ steps.meta.outputs.tags }}
 
 
-  # https://github.com/recipeer/docs/blob/develop/workflows/discord-notifications.md
   notify:
   notify:
-    name: Discord notification
-    uses: recipeer/docs/.github/workflows/discord.yml@develop
+    name: Send Discord workflow notification
+    runs-on: ubuntu-latest
     needs: build
     needs: build
-    secrets: inherit
-    if: ${{ always() }}
-    with:
-      repository: ${{ github.repository }}
-      result: ${{ needs.build.result }}
-      run_id: ${{ github.run_id }}
-      run_number: ${{ github.run_number }}
-      workflow: ${{ github.workflow }}
+    steps:
+      - name: Send notification
+        uses: annybs/action-notify-discord@v1
+        if: ${{ always() }}
+        with:
+          repository: ${{ github.repository }}
+          result: ${{ needs.build.result }}
+          run-id: ${{ github.run_id }}
+          run-number: ${{ github.run_number }}
+          webhook-url: ${{ secrets.DISCORD_WEBHOOK }}
+          workflow: ${{ github.workflow }}

+ 0 - 71
.github/workflows/deploy.yml

@@ -1,71 +0,0 @@
-# Deploy short URL service to a server
-#
-# nginx-proxy should be deployed first: https://github.com/recipeer/nginx-proxy
-
-name: Deploy
-
-on:
-  workflow_dispatch:
-    inputs:
-      environment:
-        description: 'Environment'
-        required: true
-        type: environment
-      tag:
-        description: 'Image tag'
-        required: true
-        default: develop
-
-env:
-  SERVICE_IMAGE: ghcr.io/recipeer/short-url-service:${{ inputs.tag }}
-  TARGET_START_SH: /tmp/short-url-service.start-${{ github.run_number }}.sh
-
-jobs:
-  deploy:
-    name: Deploy
-    runs-on: ubuntu-latest
-    environment: ${{ inputs.environment }}
-    steps:
-      - name: Checkout repository
-        uses: actions/checkout@v4
-
-      - name: Prepare id_rsa
-        run: echo "${{ secrets.DEPLOY_KEY }}" > id_rsa && chmod 600 id_rsa
-
-      - name: Prepare deployment script
-        run: |
-          export CSV="${{ vars.CSV }}"
-          export NETWORK=${{ vars.NETWORK }}
-          export SERVICE_CONTAINER=${{ vars.SERVICE_CONTAINER }}
-          export SERVICE_HOST=${{ vars.SERVICE_HOST }}
-          export SERVICE_IMAGE=${{ env.SERVICE_IMAGE }}
-          export SERVICE_NETWORK_ACCESS=${{ vars.SERVICE_NETWORK_ACCESS }}
-          envsubst < .deploy/start.sh.template | sed 's/£/$/g' > .deploy/start.sh
-
-      - name: Import target SSH public key
-        run: |
-          TARGET=$(echo "${{ vars.SSH_TARGET }}" | awk -F@ '{ print $2 }')
-          mkdir -p ~/.ssh && ssh-keyscan ${TARGET} >> ~/.ssh/known_hosts
-
-      - name: Copy deployment script to server
-        run: scp -vi id_rsa .deploy/start.sh ${{ vars.SSH_TARGET }}:${{ env.TARGET_START_SH }}
-
-      - name: Run deployment script
-        run: ssh -i id_rsa ${{ vars.SSH_TARGET }} bash ${{ env.TARGET_START_SH }}
-
-      - name: Cleanup deployment script
-        run: ssh -i id_rsa ${{ vars.SSH_TARGET }} rm ${{ env.TARGET_START_SH }}
-
-  # https://github.com/recipeer/docs/blob/develop/workflows/discord-notifications.md
-  notify:
-    name: Discord notification
-    uses: recipeer/docs/.github/workflows/discord.yml@develop
-    needs: deploy
-    secrets: inherit
-    if: ${{ always() }}
-    with:
-      repository: ${{ github.repository }}
-      result: ${{ needs.deploy.result }}
-      run_id: ${{ github.run_id }}
-      run_number: ${{ github.run_number }}
-      workflow: ${{ github.workflow }}