Add CI/CD for auto-deployment of blog
All checks were successful
Build and Push Docker Image / build (push) Successful in 3m23s
All checks were successful
Build and Push Docker Image / build (push) Successful in 3m23s
This commit is contained in:
46
.gitea/workflows/deploy.yml
Normal file
46
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,46 @@
|
||||
name: Deploy to Nomad
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Build and Push Docker Image"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
env:
|
||||
NOMAD_ADDR: ${{ secrets.NOMAD_ADDR }}
|
||||
NOMAD_TOKEN: ${{ secrets.NOMAD_TOKEN }}
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Get image tag from git SHA
|
||||
id: tag
|
||||
run: |
|
||||
image_tag=$(git rev-parse --short HEAD)
|
||||
echo "image_tag=$image_tag" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Update image tag in job definition
|
||||
run: |
|
||||
# Replace the image tag placeholder with actual tag
|
||||
jq '.Job.TaskGroups[0].Tasks[0].Config.image |= sub(":.*"; ":${{ steps.tag.outputs.image_tag }}")' \
|
||||
blog.nomad.json > blog.nomad.final.json
|
||||
|
||||
- name: Submit job via Nomad API
|
||||
run: |
|
||||
curl -s -X POST \
|
||||
-H "X-Nomad-Token: ${{ env.NOMAD_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d @blog.nomad.final.json \
|
||||
"${{ env.NOMAD_ADDR }}/v1/jobs"
|
||||
|
||||
- name: Verify deployment
|
||||
run: |
|
||||
echo "Waiting for deployment to stabilize..."
|
||||
sleep 5
|
||||
curl -X GET \
|
||||
-H "X-Nomad-Token: ${{ env.NOMAD_TOKEN }}" \
|
||||
"${{ env.NOMAD_ADDR }}/v1/job/blog"
|
||||
Reference in New Issue
Block a user