From aca87e3db1ce1900c062bc6f8ad9808682cd21ee Mon Sep 17 00:00:00 2001 From: Liam Pietralla Date: Sun, 19 Oct 2025 21:26:43 +1100 Subject: [PATCH 1/5] added noamad deployment --- .github/workflows/pipeline.yml | 26 +++++----------- infra/nomad/code-snippets.nomad.hcl | 46 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 infra/nomad/code-snippets.nomad.hcl diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index ab61bb2..70f2051 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -46,6 +46,7 @@ jobs: images: liamsgit.dev/LiamPietralla/code-snippets tags: | type=raw,value=latest + type=sha,value=${{ github.sha }} - name: Login to Registry uses: docker/login-action@v3 @@ -79,24 +80,13 @@ jobs: echo "$SSH_PRIVATE_KEY" > private.key sudo chmod 400 private.key - - name: Write Ansible Inventory To File - env: - APP_HOST: ${{ secrets.APP_HOST }} - run: | - echo "[app]" > hosts.ini - echo "$APP_HOST" >> hosts.ini + - name: Setup Nomad + uses: hashicorp/setup-nomad@main + with: + nomad_version: '1.10.5' - - name: Install Ansible + - name: Deploy Job to Nomad run: | - sudo apt-add-repository ppa:ansible/ansible -y - sudo apt-get update -y - sudo apt-get install ansible -y - - - name: Run Ansible Playbook to Configure Servers - run: | - export ANSIBLE_HOST_KEY_CHECKING=False # Disable host key checking - ansible-playbook infra/ansible/deploy-playbook.yml --private-key private.key --inventory hosts.ini + nomad job run -var="version=${{ github.sha }}" infra/nomad/code-snippets.nomad.hcl env: - APP_HOST: ${{ secrets.APP_HOST }} - REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} - REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} \ No newline at end of file + NOMAD_ADDR: ${{ secrets.NOMAD_ADDR }} diff --git a/infra/nomad/code-snippets.nomad.hcl b/infra/nomad/code-snippets.nomad.hcl new file mode 100644 index 0000000..ccbfea5 --- /dev/null +++ b/infra/nomad/code-snippets.nomad.hcl @@ -0,0 +1,46 @@ +job "code-snippets" { + datacenters = ["dc1"] + type = "service" + + variable "version" { + type = string + default = "latest" + } + + group "code-snippets" { + count = 1 + + network { + port "http" { + to = 80 + } + } + + task "code-snippets" { + driver = "docker" + + config { + image = "liamsgit.dev/LiamPietralla/code-snippets:${var.version}" + force_pull = true + ports = ["http"] + } + + service { + name = "code-snippets" + port = "http" + tags = [ + "traefik.enable=true", + "traefik.http.routers.code-snippets.rule=PathPrefix(`/`)", + "traefik.http.routers.code-snippets.entrypoints=p5003" + ] + + check { + type = "http" + path = "/" + interval = "10s" + timeout = "2s" + } + } + } + } +} \ No newline at end of file From acee9670d0c667aadc4dd1d11a9df5874f85bd66 Mon Sep 17 00:00:00 2001 From: Liam Pietralla Date: Sun, 19 Oct 2025 21:39:32 +1100 Subject: [PATCH 2/5] fix var --- infra/nomad/code-snippets.nomad.hcl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/infra/nomad/code-snippets.nomad.hcl b/infra/nomad/code-snippets.nomad.hcl index ccbfea5..93b4dab 100644 --- a/infra/nomad/code-snippets.nomad.hcl +++ b/infra/nomad/code-snippets.nomad.hcl @@ -1,12 +1,12 @@ +variable "version" { +type = string +default = "latest" +} + job "code-snippets" { datacenters = ["dc1"] type = "service" - variable "version" { - type = string - default = "latest" - } - group "code-snippets" { count = 1 From 6e5d4e39e78f5f9a418a7b3c4e4dac62fdeff6b6 Mon Sep 17 00:00:00 2001 From: Liam Pietralla Date: Sun, 19 Oct 2025 21:43:39 +1100 Subject: [PATCH 3/5] try fix job nomad --- .github/workflows/pipeline.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 70f2051..9a21bc1 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -87,6 +87,5 @@ jobs: - name: Deploy Job to Nomad run: | + export NOMAD_ADDR=${{ secrets.NOMAD_ADDR }} nomad job run -var="version=${{ github.sha }}" infra/nomad/code-snippets.nomad.hcl - env: - NOMAD_ADDR: ${{ secrets.NOMAD_ADDR }} From 52427c453e5617a6cb4dd615f66acbcebeb25272 Mon Sep 17 00:00:00 2001 From: Liam Pietralla Date: Sun, 19 Oct 2025 21:47:12 +1100 Subject: [PATCH 4/5] change to use var --- .github/workflows/pipeline.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 9a21bc1..7545143 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -87,5 +87,6 @@ jobs: - name: Deploy Job to Nomad run: | - export NOMAD_ADDR=${{ secrets.NOMAD_ADDR }} nomad job run -var="version=${{ github.sha }}" infra/nomad/code-snippets.nomad.hcl + env: + NOMAD_ADDR: ${{ vars.NOMAD_ADDR }} From 87d81bb447335f0d99034276f24f60c33e86034d Mon Sep 17 00:00:00 2001 From: Liam Pietralla Date: Mon, 20 Oct 2025 12:20:05 +1100 Subject: [PATCH 5/5] revert so can deploy --- .github/workflows/pipeline.yml | 40 ++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 7545143..29f2a9f 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -80,13 +80,35 @@ jobs: echo "$SSH_PRIVATE_KEY" > private.key sudo chmod 400 private.key - - name: Setup Nomad - uses: hashicorp/setup-nomad@main - with: - nomad_version: '1.10.5' - - - name: Deploy Job to Nomad - run: | - nomad job run -var="version=${{ github.sha }}" infra/nomad/code-snippets.nomad.hcl + - name: Write Ansible Inventory To File env: - NOMAD_ADDR: ${{ vars.NOMAD_ADDR }} + APP_HOST: ${{ secrets.APP_HOST }} + run: | + echo "[app]" > hosts.ini + echo "$APP_HOST" >> hosts.ini + + - name: Install Ansible + run: | + sudo apt-add-repository ppa:ansible/ansible -y + sudo apt-get update -y + sudo apt-get install ansible -y + + - name: Run Ansible Playbook to Configure Servers + run: | + export ANSIBLE_HOST_KEY_CHECKING=False # Disable host key checking + ansible-playbook infra/ansible/deploy-playbook.yml --private-key private.key --inventory hosts.ini + env: + APP_HOST: ${{ secrets.APP_HOST }} + REGISTRY_USERNAME: ${{ secrets.DOCKER_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + + # - name: Setup Nomad + # uses: hashicorp/setup-nomad@main + # with: + # nomad_version: '1.10.5' + + # - name: Deploy Job to Nomad + # run: | + # nomad job run -var="version=${{ github.sha }}" infra/nomad/code-snippets.nomad.hcl + # env: + # NOMAD_ADDR: ${{ vars.NOMAD_ADDR }}