Skip to content

Commit

Permalink
ATOR-193 - Add multi env deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
yumirkov committed Mar 28, 2024
1 parent 97f2b45 commit 32d58b4
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 14 deletions.
10 changes: 6 additions & 4 deletions .github/actions/build-and-push/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ inputs:
required: true
docker-password:
required: true
docker-tag:
required: true

runs:
using: "composite"
steps:
- name: Log in to Docker Hub
uses: docker/login-action@v3
uses: docker/login-action@v1
with:
username: ${{ inputs.docker-username }}
password: ${{ inputs.docker-password }}

- name: Build and push Docker image of service
uses: docker/build-push-action@v3
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
file: ./docker/Dockerfile
push: true
tags: ${{ inputs.docker-username }}/metrics-service:${{ github.sha }},${{ inputs.docker-username }}/metrics-service:latest
tags: ${{ inputs.docker-username }}/metrics-service:${{ github.sha }},${{ inputs.docker-username }}/metrics-service:${{ inputs.docker-tag }}
5 changes: 3 additions & 2 deletions .github/actions/deploy/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: 'Deploy new version'

inputs:
environment:
required: true
nomad-cacert:
required: true
nomad-token:
Expand All @@ -20,4 +21,4 @@ runs:
run: |
curl -L https://releases.hashicorp.com/nomad/1.6.3/nomad_1.6.3_linux_amd64.zip -o nomad.zip
unzip nomad.zip
./nomad job run operations/deploy.hcl
./nomad job run operations/deploy-${{ inputs.environment }}.hcl
8 changes: 5 additions & 3 deletions .github/workflows/build-and-deploy.yml → .github/workflows/dev.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Build and Deploy
name: DEV - Build and Deploy

on:
pull_request:
branches:
- development
push:
branches:
- development
workflow_dispatch:

jobs:
Expand All @@ -13,13 +16,12 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Build and push
uses: ./.github/actions/build-and-push
with:
docker-username: ${{ secrets.DOCKER_HUB_USERNAME }}
docker-password: ${{ secrets.DOCKER_HUB_PASSWORD }}

docker-tag: latest-dev
- name: Deploy
uses: ./.github/actions/deploy
with:
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/live.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: LIVE - Tag and Deploy

on:
# pull_request:
# branches:
# - development
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Github Container Registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Tag latest
run: |
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/metrics-service:latest-stage
docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/metrics-service:latest-stage ${{ secrets.DOCKER_HUB_USERNAME }}/metrics-service:latest
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/metrics-service:latest
- name: Deploy
uses: ./.github/actions/deploy
with:
environment: live
nomad-cacert: operations/admin-ui-ca.crt
nomad-token: ${{ secrets.NOMAD_TOKEN_METRICS_SERVICE_DEPLOY }}
nomad-addr: ${{ secrets.NOMAD_DEPLOY_ADDR }}
31 changes: 31 additions & 0 deletions .github/workflows/stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: STAGE - Build and Deploy

on:
pull_request:
branches:
- development
push:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Build and push
uses: ./.github/actions/build-and-push
with:
docker-username: ${{ secrets.DOCKER_HUB_USERNAME }}
docker-password: ${{ secrets.DOCKER_HUB_PASSWORD }}
docker-tag: latest-stage
- name: Deploy
uses: ./.github/actions/deploy
with:
environment: stage
nomad-cacert: operations/admin-ui-ca.crt
nomad-token: ${{ secrets.NOMAD_TOKEN_METRICS_SERVICE_DEPLOY }}
nomad-addr: ${{ secrets.NOMAD_DEPLOY_ADDR }}
65 changes: 65 additions & 0 deletions operations/deploy-dev.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
job "metrics-service-dev" {
datacenters = ["ator-fin"]
type = "service"
namespace = "ator-network"

group "metrics-service-dev-group" {
count = 1

network {
mode = "bridge"
port "http-port" {
static = 9033
to = 3000
#host_network = "wireguard"
}
}

task "metrics-service-dev-task" {
driver = "docker"

template {
data = <<EOH
{{- range nomadService "victoriametrics-db" }}
VICTORIA_METRICS_ADDRESS="http://{{ .Address }}:{{ .Port }}"
{{ end -}}
CLUSTER="local"
ENV="main"
INSTANCE="10.1.244.1:9190"
JOB="consulagentonionoo"
EOH
destination = "secrets/file.env"
env = true
}

config {
image = "svforte/metrics-service:latest-dev"
force_pull = true
ports = ["http-port"]
}

resources {
cpu = 256
memory = 256
}

service {
name = "metrics-service-dev"
port = "http-port"
check {
name = "Metrics service check"
type = "tcp"
port = "http-port"
path = "/"
interval = "10s"
timeout = "10s"
check_restart {
limit = 10
grace = "30s"
}
}
}
}

}
}
10 changes: 5 additions & 5 deletions operations/deploy.hcl → operations/deploy-live.hcl
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
job "metrics-service" {
job "metrics-service-live" {
datacenters = ["ator-fin"]
type = "service"
namespace = "ator-network"

group "metrics-service-group" {
group "metrics-service-live-group" {
count = 1

network {
mode = "bridge"
port "http-port" {
static = 9033
static = 9233
to = 3000
#host_network = "wireguard"
}
}

task "metrics-service-task" {
task "metrics-service-live-task" {
driver = "docker"

template {
Expand Down Expand Up @@ -44,7 +44,7 @@ job "metrics-service" {
}

service {
name = "metrics-service"
name = "metrics-service-live"
port = "http-port"
check {
name = "Metrics service check"
Expand Down
65 changes: 65 additions & 0 deletions operations/deploy-stage.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
job "metrics-service-stage" {
datacenters = ["ator-fin"]
type = "service"
namespace = "ator-network"

group "metrics-service-stage-group" {
count = 1

network {
mode = "bridge"
port "http-port" {
static = 9133
to = 3000
#host_network = "wireguard"
}
}

task "metrics-service-stage-task" {
driver = "docker"

template {
data = <<EOH
{{- range nomadService "victoriametrics-db" }}
VICTORIA_METRICS_ADDRESS="http://{{ .Address }}:{{ .Port }}"
{{ end -}}
CLUSTER="local"
ENV="main"
INSTANCE="10.1.244.1:9190"
JOB="consulagentonionoo"
EOH
destination = "secrets/file.env"
env = true
}

config {
image = "svforte/metrics-service:latest-stage"
force_pull = true
ports = ["http-port"]
}

resources {
cpu = 256
memory = 256
}

service {
name = "metrics-service-stage"
port = "http-port"
check {
name = "Metrics service check"
type = "tcp"
port = "http-port"
path = "/"
interval = "10s"
timeout = "10s"
check_restart {
limit = 10
grace = "30s"
}
}
}
}

}
}

0 comments on commit 32d58b4

Please sign in to comment.