First real commit
Some checks failed
Build, Push, and Deploy to Nomad / docker-nomad (push) Failing after 1m5s

This commit is contained in:
Henrik Jess
2024-12-10 15:16:17 +01:00
parent c5c7b99caa
commit a5a155f238
7 changed files with 144 additions and 8 deletions

63
.gitea/workflows/main.yml Normal file
View File

@@ -0,0 +1,63 @@
name: Build, Push, and Deploy to Nomad
on:
push:
branches:
- main
jobs:
docker-nomad:
runs-on: self-hosted
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Log in to Container Registry
run: echo ${{ secrets.password }} | docker login registry.i80.dk -u ${{ secrets.username }} --password-stdin
- name: Build Docker Image
run: |
COMMIT_HASH=$(git rev-parse --short HEAD)
docker build -t registry.i80.dk/gitea/lifefaq:latest -t registry.i80.dk/gitea/lifefaq:${COMMIT_HASH} .
- name: Push Docker Image
run: |
COMMIT_HASH=$(git rev-parse --short HEAD)
echo "registry.i80.dk/gitea/lifefaq:latest"
echo "registry.i80.dk/gitea/lifefaq:${COMMIT_HASH}"
docker push registry.i80.dk/gitea/lifefaq:${COMMIT_HASH}
docker push registry.i80.dk/gitea/lifefaq:latest
- name: Validate Nomad Job
env:
NOMAD_ADDR: https://nomad.i80.dk
run: nomad job validate .gitea/workflows/nomad-job.hcl
- name: Stop old deployment
env:
NOMAD_ADDR: https://nomad.i80.dk
run: nomad job stop -purge -no-shutdown-delay lifefaq
continue-on-error: true
- name: Apply Nomad Job
env:
NOMAD_ADDR: https://nomad.i80.dk
run: nomad job run .gitea/workflows/nomad-job.hcl
- name: Update Nginx Configuration
run: ssh runner@nomad sudo /opt/nginx_updater/venv/bin/python3 /opt/nginx_updater/nginx_updater.py lifefaq
- name: Update Forwarder Configuration
run: ssh runner@nomad sudo /opt/nginx_updater/venv/bin/python3 /opt/nginx_updater/update_forwarder.py lifefaq
# - name: Restart Nomad Job
# env:
# NOMAD_ADDR: https://nomad.i80.dk
# run: |
# nomad job stop lifefaq
# sleep 5 # Optional: Wait to ensure the old allocation is stopped
# nomad job run .gitea/workflows/nomad-job.hcl

View File

@@ -0,0 +1,60 @@
job "lifefaq" {
region = "global"
datacenters = ["dc1"]
type = "service"
update {
stagger = "60s"
max_parallel = 1
progress_deadline = "6m"
}
group "lifefaq-group" {
count = 1
network {
port "port-app" {
to = 9210 # Internal application port
}
}
# Register the service with Consul
service {
provider = "consul"
name = "lifefaq"
port = "port-app"
# Traefik-specific tags for routing
tags = [
"PORT=${NOMAD_PORT_port-app}"
]
# Define a health check using TCP
check {
name = "tcp_check"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
task "lifefaq-task" {
driver = "docker"
config {
image = "registry.i80.dk/gitea/lifefaq:latest"
ports = ["port-app"]
}
env {
APP_ENV = "production"
PORT = "${NOMAD_PORT_port-app}"
}
resources {
cpu = 250
memory = 80
}
}
}
}