-
Notifications
You must be signed in to change notification settings - Fork 1
112 lines (95 loc) · 3.81 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Deploy
on:
workflow_dispatch:
inputs:
image:
description: "Image Name"
required: true
default: "cloud-registry.simulprod.com/grid/grid-bot"
image_tag:
description: "Image Tag"
required: true
default: "latest"
registry:
description: "Docker Registry"
required: true
default: "cloud-registry.simulprod.com"
nomad_job_name:
description: "Nomad Job Name"
required: true
default: "grid-bot"
nomad_enviroment:
description: "Nomad Environment"
required: true
default: "production"
type: choice
options:
- "production"
- "staging"
nomad_resources:
description: "Nomad Resources (CPU:Memory)"
required: true
default: "2000:1024"
permissions:
deployments: write
jobs:
deploy:
runs-on: grid-bot-infra
env:
IMAGE: ${{ github.event.inputs.image || 'cloud-registry.simulprod.com/grid/grid-bot'}}
IMAGE_TAG: ${{ github.event.inputs.image_tag || 'latest' }}
DOCKER_REGISTRY: ${{ github.event.inputs.registry || 'cloud-registry.simulprod.com' }}
NOMAD_ADDR: ${{ vars.NOMAD_ADDR }}
NOMAD_TOKEN: ${{ secrets.NOMAD_TOKEN }}
NOMAD_ENVIRONMENT: ${{ github.event.inputs.nomad_enviroment || 'production' }}
NOMAD_JOB_NAME: ${{ github.event.inputs.nomad_job_name || 'grid-bot' }}-${{ (github.event.inputs.nomad_enviroment || 'production') == 'production' && 'prod' || 'stage' }}
NOMAD_RESOURCES: ${{ github.event.inputs.nomad_resources || '2000:1024' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Nomad CLI
uses: nferch/setup-nomad@v4.0.0
env:
NOMAD_TLS_SKIP_VERIFY: 1
- name: Set Initial GitHub Deployment Status
uses: chrnorm/deployment-action@v2
id: deployment
continue-on-error: true
with:
token: "${{ github.token }}"
environment: ${{ env.NOMAD_ENVIRONMENT }}
environment-url: "${{ env.NOMAD_ADDR }}/ui/jobs/${{ env.NOMAD_JOB_NAME }}"
description: "Version: ${{ env.IMAGE_TAG }}"
- name: Deploy to Nomad
env:
NOMAD_TLS_SKIP_VERIFY: 1
id: deploy
continue-on-error: true
run: |
# Template file is at ${workspace}/nomad/grid-bot.nomad
# Replace {{{IMAGE_NAME}}} and {{{IMAGE_TAG}}} with the actual values
# Create a temporary file
NOMAD_JOB_FILE=$(mktemp)
# Replace the template with the actual values
sed -e "s,{{{IMAGE_NAME}}},${{ env.IMAGE }}," \
-e "s/{{{IMAGE_TAG}}}/${{ env.IMAGE_TAG }}/" \
-e "s/{{{NOMAD_JOB_NAME}}}/${{ env.NOMAD_JOB_NAME }}/" \
-e "s/{{{NOMAD_ENVIRONMENT}}}/${{ env.NOMAD_ENVIRONMENT }}/" \
-e "s/{{{NOMAD_CPU}}}/$(echo ${{ env.NOMAD_RESOURCES }} | cut -d: -f1)/" \
-e "s/{{{NOMAD_MEMORY}}}/$(echo ${{ env.NOMAD_RESOURCES }} | cut -d: -f2)/" \
./nomad/grid-bot.nomad > $NOMAD_JOB_FILE
# Run the job but do not wait for longer than 5 minutes
nomad job run $NOMAD_JOB_FILE
# Cleanup
rm $NOMAD_JOB_FILE
- name: Set GitHub Deployment Status
uses: chrnorm/deployment-status@v2
continue-on-error: true
with:
token: "${{ github.token }}"
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
environment-url: "${{ steps.deployment.outputs.environment_url }}"
description: "Version: ${{ env.IMAGE_TAG }}"
# If the "deploy" step fails, the deployment status will be set to "failure"
# If the "deploy" step succeeds, the deployment status will be set to "success"
state: "${{ steps.deploy.outcome }}"