diff --git a/.gitea/workflows/plan-and-apply.yaml b/.gitea/workflows/plan-and-apply.yaml index ca61cc0..7e922b4 100644 --- a/.gitea/workflows/plan-and-apply.yaml +++ b/.gitea/workflows/plan-and-apply.yaml @@ -15,6 +15,7 @@ env: TF_PLUGIN_CACHE_DIR: ${{ gitea.workspace }}/.terraform.d/plugin-cache TF_IN_AUTOMATION: true TF_CLI_ARGS: "-no-color" + NOMAD_ADDR: "${{ vars.NOMAD_ADDR }}" NOMAD_TOKEN: "${{ secrets.NOMAD_TOKEN }}" PG_CONN_STR: "${{ secrets.PG_CONN_STR }}" @@ -44,6 +45,11 @@ jobs: id: plan run: terraform plan -out=tfplan continue-on-error: true + - uses: hashicorp/setup-nomad@main + - name: Install jq + run: sudo apt-get update && sudo apt-get install -y jq + - name: Nomad Validate + run: terraform show -json tfplan | jq -r '.planned_values.root_module.child_modules[].resources[].values.jobspec' | nomad job validate -json - - uses: actions/github-script@v7 if: github.event_name == 'pull_request' env: diff --git a/main.tf b/main.tf index 6fc242e..ba724b0 100644 --- a/main.tf +++ b/main.tf @@ -5,3 +5,7 @@ terraform { module "dummy" { source = "./modules/dummy" } + +module "media-centre" { + source = "./modules/media-centre" +} diff --git a/modules/media-centre/jobspec.json b/modules/media-centre/jobspec.json new file mode 100644 index 0000000..b95aa42 --- /dev/null +++ b/modules/media-centre/jobspec.json @@ -0,0 +1,73 @@ +{ + "ID": "media-centre", + "Name": "Media Centre", + "TaskGroups": [ + { + "Name": "Media Servers", + "Tasks": [ + { + "Name": "Jellyfin", + "Type": "docker", + "Config": { + "image": "lscr.io/linuxserver/jellyfin:latest", + "ports": [ + "jellyfin" + ], + "mounts": [ + { + "type": "volume", + "target": "/media", + "VolumeOptions": { + "driver": "local", + "driver_opts": { + "type": "nfs", + "o": "addr=martinibar.lan,nolock,soft,rw", + "device": ":/volume1/docker" + } + } + }, + { + "type": "volume", + "target": "/config", + "source": "jellyfin-config" + } + ] + }, + "Env": { + "TZ": "Europe/London", + "PUID": "985", + "PGID": "997", + "JELLYFIN_PublishedServerUrl": "192.168.1.5" + }, + "Resources": { + "CPU": 3100, + "MemoryMB": 8129 + } + } + ], + "Services": [ + { + "Name": "Jellyfin", + "Provider": "nomad", + "PortLabel": "jellyfin", + "Tags": [ + "traefik.enable=true", + "traefik.http.routers.jellyfin.entrypoints=websecure", + "traefik.http.routers.jellyfin.rule=Host(`jellyfin.brmartin.co.uk`)" + ] + + } + ], + "Networks": [ + { + "DynamicPorts": [ + { + "Label": "jellyfin", + "To": 8096 + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/modules/media-centre/main.tf b/modules/media-centre/main.tf new file mode 100644 index 0000000..f285e4d --- /dev/null +++ b/modules/media-centre/main.tf @@ -0,0 +1,4 @@ +resource "nomad_job" "media-centre" { + jobspec = file("${path.module}/jobspec.json") + json = true +}