Skip to content

Commit 3b59256

Browse files
authored
Merge pull request #6 from ncode/juliano/development
job to launch nomad and docker to validate the rules
2 parents af1656a + ab7e95a commit 3b59256

File tree

6 files changed

+122
-1
lines changed

6 files changed

+122
-1
lines changed

configs/development/Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Use Oracle Linux 9 as the base image
2+
FROM oraclelinux:9
3+
4+
# Set environment variables
5+
ENV NOMAD_VERSION=1.8.2
6+
ENV CNI_PLUGINS_VERSION=v1.5.1
7+
ENV ARCH=arm64
8+
9+
# Install necessary packages
10+
RUN dnf update -y && \
11+
dnf install -y \
12+
curl \
13+
git \
14+
unzip \
15+
tcpdump \
16+
bind-utils \
17+
iproute \
18+
iputils \
19+
iptables \
20+
ipset \
21+
ca-certificates && \
22+
dnf clean all
23+
24+
# Download and install Nomad for the appropriate architecture
25+
RUN curl -fsSL https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_${ARCH}.zip -o nomad.zip && \
26+
mkdir -p /etc/nomad /var/lib/nomad && \
27+
unzip nomad.zip && \
28+
rm nomad.zip && \
29+
mv nomad /usr/local/bin/nomad
30+
31+
# Download and install CNI plugins for the appropriate architecture
32+
RUN mkdir -p /opt/cni/bin /opt/cni/config && \
33+
curl -L https://github.com/containernetworking/plugins/releases/download/${CNI_PLUGINS_VERSION}/cni-plugins-linux-${ARCH}-${CNI_PLUGINS_VERSION}.tgz | tar -C /opt/cni/bin -xz
34+
35+
# Create a basic CNI configuration
36+
RUN mkdir -p /opt/cni/config
37+
COPY entrypoint.sh /entrypoint.sh
38+
COPY my-network.conflist /opt/cni/config/my-network.conflist
39+
COPY outbound /opt/cni/bin/outbound
40+
COPY config.hcl /etc/nomad/config.hcl
41+
42+
# Expose Nomad's default ports
43+
EXPOSE 4646 4647 4648 4649
44+
45+
# Set the entrypoint to start Nomad in development mode
46+
ENTRYPOINT ["/entrypoint.sh"]

configs/development/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
all: build docker-build down up
44

55
build:
6-
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" ../../plugins/output
6+
GOOS=linux GOARCH=arm64 go build -o outbound -ldflags="-s -w" ../../
77

88
docker-build:
9+
cp -f ../my-network.conflist .
910
docker build -t ncode/cni-output:dev .
11+
rm my-network.conflist
12+
rm outbound
1013

1114
up:
1215
docker compose up

configs/development/config.hcl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server {
2+
enabled = true
3+
bootstrap_expect = 1
4+
}
5+
6+
datacenter = "dc1"
7+
region = "rg1"
8+
bind_addr = "0.0.0.0"
9+
data_dir = "/var/lib/nomad"
10+
11+
client {
12+
enabled = true
13+
cpu_total_compute = 2000
14+
}
15+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
nomad:
3+
image: ncode/cni-output:dev
4+
ports:
5+
- "4646:4646" # HTTP API
6+
- "4647:4647" # RPC
7+
- "4648:4648" # Serf WAN
8+
volumes:
9+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
10+
privileged: true
11+
deploy:
12+
resources:
13+
limits:
14+
cpus: 2
15+
memory: 512M
16+
reservations:
17+
cpus: 2
18+
memory: 512M

configs/development/entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
echo 1 > /proc/sys/net/ipv4/ip_forward
4+
nomad agent -config=/etc/nomad

configs/dig-job.hcl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
job "dig-job" {
2+
datacenters = ["dc1"]
3+
4+
group "dig-group" {
5+
network {
6+
mode = "cni/my-network"
7+
}
8+
9+
task "dig-task" {
10+
driver = "exec"
11+
12+
config {
13+
command = "/bin/bash"
14+
args = ["-c", "/local/dig-loop.sh"]
15+
}
16+
17+
template {
18+
destination = "local/dig-loop.sh"
19+
perms = "755"
20+
data = <<-EOT
21+
#!/bin/bash
22+
while true ; do
23+
dig google.com
24+
sleep 5
25+
done
26+
EOT
27+
}
28+
29+
resources {
30+
cpu = 100
31+
memory = 20
32+
}
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)