Skip to content

Commit

Permalink
chore: setup nomad in github action
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrrt committed Nov 11, 2024
1 parent 56c1c3e commit c4e9f24
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 16 deletions.
35 changes: 35 additions & 0 deletions .github/actions/setup-nomad/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Setup Nomad
description: Setup Local Nomad cluster for use in GitHub Actions

runs:
using: "composite"
steps:
- name: Start Nomad cluster in container
run: |
docker run -d \
--name nomad-cluster \
-p 4646:4646 \
multani/nomad:latest
shell: bash

# Wait for the Nomad cluster to be ready
- name: Wait for Nomad to start
run: |
for i in {1..10}; do
if docker exec nomad-cluster nomad node status &> /dev/null; then
echo "Nomad is ready"
exit 0
fi
echo "Waiting for Nomad to be ready..."
sleep 3
done
echo "Nomad did not start in time" >&2
exit 1
shell: bash

post:
- name: Stop and remove Nomad container
run: |
docker stop nomad-cluster
docker rm nomad-cluster
shell: bash
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

- name: Setup Nomad
uses: ./.github/actions/setup-nomad

- name: CI
run: make ci
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
GO_BIN := go
# project sources
ROOT_PRJ := .
# test targets options
TEST_OPTS_WITH_LOGS := -v

.PHONY: tidy
tidy:
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

### Start Nomad service

```bash
make start_nomad
```

For the sake of simplicity and portability, nomad has been dockerized and configuration added to a compose file.

```bash
Expand All @@ -23,11 +27,10 @@ Once nomad agent has been started, the nomad UI can be accessed via http://local
make dev
```


### Start E2E

```bash
//
make ci
```

## Comments
Expand Down
1 change: 0 additions & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ services:
command: agent -dev
privileged: true
network_mode: host
# network_mode: bridge
environment:
NOMAD_LOCAL_CONFIG: |
data_dir = "/nomad/data/"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22.2

require (
github.com/gin-gonic/gin v1.10.0
github.com/google/uuid v1.6.0
github.com/hashicorp/nomad/api v0.0.0-20241108174938-0714353324cd
github.com/stretchr/testify v1.9.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MG
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/cronexpr v1.1.2 h1:wG/ZYIKT+RT3QkOdgYc+xsKWVRgnxJ1OJtjjy84fJ9A=
Expand Down
14 changes: 3 additions & 11 deletions nomad/nomad.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package main
package nomad

import (
"fmt"
"log"
"time"

"github.com/google/uuid"
"github.com/hashicorp/nomad/api"
)

func stringPtr(s string) *string {
return &s
}

func intToPtr(i int) *int {
return &i
}

func createAJobAndGetUri() {
// Create a new Nomad client
client, err := api.NewClient(api.DefaultConfig())
Expand Down Expand Up @@ -104,8 +97,7 @@ func registerJobAndGetAllocationID(client *api.Client, job *api.Job) (string, er
func createServiceJob() *api.Job {
// Define the service job
job := &api.Job{
// ID must be uuid
ID: stringPtr("hello-world"),
ID: stringPtr(uuid.New().String()),
Name: stringPtr("noaas-agent"),
Type: stringPtr("service"),
Datacenters: []string{"*"}, // Specifies that this job can run in any datacenter
Expand Down
9 changes: 9 additions & 0 deletions nomad/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nomad

func stringPtr(s string) *string {
return &s
}

func intToPtr(i int) *int {
return &i
}

0 comments on commit c4e9f24

Please sign in to comment.