Skip to content

A GitHub action to collect Hashicorp Nomad logs from a given job.

License

Notifications You must be signed in to change notification settings

younited/nomad-logs-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

nomad-logs-action

Small GitHub Action that makes requests to a Hashicorp Nomad server and collects logs from a given job.

Usage

Get logs from a service job

name: Get logs from Nomad Job
on: [push]
jobs:
  logs:
    name: Nomad Logs
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Get logs from Nomad
        uses: younited/nomad-logs-action
        with:
          token: ${{ secrets.YOUR_NOMAD_SECRET }}
          address: ${{ secrets.YOUR_NOMAD_SERVER }}
          job: example-job

Get logs from a parameterized job in a specific namespace and always complete successfully

name: Get logs from Nomad Job
on: [push]
jobs:
  logs:
    name: Nomad Logs
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Get logs from Nomad
        uses: younited/nomad-logs-action
        with:
          token: ${{ secrets.YOUR_NOMAD_SECRET }}
          address: ${{ secrets.YOUR_NOMAD_SERVER }}
          job: parameterized-job
          namespace: my-namespace
          parameterized: true
          allow-stderr: true

Combine with vault-action

name: Get logs from Nomad Job
on: [push]
jobs:
  logs:
    name: Nomad Logs
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Get Nomad token from Hashicorp Vault
        uses: hashicorp/[email protected]
        with:
          url: ${{ secrets.YOUR_VAULT_SERVER }}
          method: approle
          roleId: ${{ secrets.VAULT_ROLE_ID }}
          secretId: ${{ secrets.VAULT_SECRET_ID }}
          secrets: |
            nomad/creds/github-action secret_id | NOMAD_TOKEN

      - name: Get logs from Nomad
        uses: younited/nomad-logs-action
        with:
          token: ${{ env.NOMAD_TOKEN }}
          address: ${{ secrets.YOUR_NOMAD_SERVER }}
          job: parameterized-job
          namespace: my-namespace
          parameterized: true

Parameters

  • token: Token used to authenticate with a nomad server
  • address: Address of the nomad server
  • namespace: Namespace of the nomad job
  • job: Name of the nomad job
  • parameterized: Set to true if the nomad job is parameterized
  • allow-stderr: Set to true so that the action completes successfully if logs are detected on stderr

Outputs

  • status: Indicates the success or failure of the running tasks
  • content: Displays the task logs from stdout or stderr

Example of displayed logs

Success (service job)

Allocation "1abcd234" (group example-1):
✅ Task example-1 successfully deployed.

Allocation "4901ffe1" (group example-2):
✅ Task example-2 successfully deployed.

Allocation "ba54b3d9" (group example-1):
✅ Task example-1 successfully deployed.

Success (parameterized job)

Allocation "c41d3bc7" (group parameterized-1):
✅ Task parameterized_task_example successfully deployed:
<PARAMETERIZED JOB OUTPUT>

Error

Allocation "47445981" (group example-1):
❌ Task example-1 failed:
2021/06/08 17:17:34 [emerg] 1#1: unknown directive "servre" in /etc/nginx/conf.d/status.conf:1
nginx: [emerg] unknown directive "servre" in /etc/nginx/conf.d/status.conf:1

Allocation "48bf3fc1" (group example-2):
✅ Task example-2 successfully deployed.

Out of Memory

Allocation "5ab5c4d8" (group example-2):
❌ Task example-2 killed due to out-of-limit resources usage.

Docker Driver Error

Allocation "490f2fc1" (group example-1):
✅ Task example-1 successfully deployed.

Allocation "d9f173e5" (group example-2):
❌ Task example-2 failed:
Failed to pull `nginx:1.19.4-oopsie`: API error (404): manifest for nginx:1.19.4-oopsie not found: manifest unknown: manifest unknown