initial commit
This commit is contained in:
14
.devcontainer/.env
Normal file
14
.devcontainer/.env
Normal file
@@ -0,0 +1,14 @@
|
||||
INFRA9METALBRIDGE_TRACING_ENABLED=false
|
||||
INFRA9METALBRIDGE_TRACING_PROVIDER=jaeger
|
||||
INFRA9METALBRIDGE_TRACING_JAEGER_ENDPOINT=http://localhost:14268/api/traces
|
||||
|
||||
INFRA9METALBRIDGE_EVENTS_SUBSCRIBER_URL="nats://nats:4222"
|
||||
INFRA9METALBRIDGE_EVENTS_SUBSCRIBER_PREFIX="com.equinixmetal"
|
||||
INFRA9METALBRIDGE_EVENTS_SUBSCRIBER_NATS_CREDSFILE=".devcontainer/nsc/nkeys/creds/LOCAL/LBAAS/USER.creds"
|
||||
|
||||
INFRA9METALBRIDGE_EVENTS_PUBLISHER_URL="nats://nats:4222"
|
||||
INFRA9METALBRIDGE_EVENTS_PUBLISHER_PREFIX="com.infratographer"
|
||||
INFRA9METALBRIDGE_EVENTS_PUBLISHER_NATS_CREDSFILE=".devcontainer/nsc/nkeys/creds/LOCAL/LBAAS/USER.creds"
|
||||
|
||||
NATS_URL="nats://nats:4222"
|
||||
NATS_CREDS=".devcontainer/nsc/nkeys/creds/LOCAL/LBAAS/USER.creds"
|
||||
31
.devcontainer/Dockerfile
Normal file
31
.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,31 @@
|
||||
# Used to install CRDB into the devcontainer
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/go:1-1.20-bullseye
|
||||
|
||||
# [Optional] Uncomment this section to install additional OS packages.
|
||||
RUN export DEBIAN_FRONTEND=noninteractive \
|
||||
&& curl https://baltocdn.com/helm/signing.asc | gpg --dearmor > /usr/share/keyrings/helm.gpg \
|
||||
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor > /usr/share/keyrings/yarn-archive-keyring.gpg \
|
||||
&& apt-get install apt-transport-https --yes \
|
||||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list \
|
||||
&& apt-get update \
|
||||
&& apt-get -y install --no-install-recommends \
|
||||
bash-completion \
|
||||
helm \
|
||||
uuid-runtime \
|
||||
postgresql-client
|
||||
|
||||
|
||||
# Install NATS Tooling
|
||||
RUN curl -o /tmp/install.sh https://raw.githubusercontent.com/nats-io/nsc/main/install.sh \
|
||||
&& chmod +x /tmp/install.sh \
|
||||
&& /tmp/install.sh -d /usr/local/bin -s - \
|
||||
&& rm -f /tmp/install.sh
|
||||
|
||||
USER vscode
|
||||
ENV NATS_CLI_VERSION=0.0.35
|
||||
RUN go install -v github.com/cweill/gotests/gotests@v1.6.0 \
|
||||
&& go install github.com/nats-io/natscli/nats@v${NATS_CLI_VERSION} \
|
||||
&& go install github.com/nats-io/nkeys/nk@latest \
|
||||
&& go install ariga.io/atlas/cmd/atlas@latest
|
||||
|
||||
USER root
|
||||
34
.devcontainer/devcontainer.json
Normal file
34
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,34 @@
|
||||
// Config reference, https://containers.dev/implementors/json_reference/
|
||||
{
|
||||
"dockerComposeFile": "docker-compose.yml",
|
||||
"service": "app",
|
||||
"shutdownAction": "stopCompose",
|
||||
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
|
||||
// Configure tool-specific properties.
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"settings": {
|
||||
"[go]": {
|
||||
"editor.defaultFormatter": "golang.go"
|
||||
},
|
||||
"go.buildTags": "testtools",
|
||||
"go.lintTool": "golangci-lint",
|
||||
"gopls": {
|
||||
"formatting.gofumpt": true,
|
||||
"formatting.local": "go.equinixmetal.net/infra9-metal-bridge"
|
||||
}
|
||||
},
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"golang.Go",
|
||||
"ms-azuretools.vscode-docker",
|
||||
"GraphQL.vscode-graphql"
|
||||
]
|
||||
}
|
||||
},
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
|
||||
"ghcr.io/devcontainers/features/sshd:1": {}
|
||||
},
|
||||
"postStartCommand": "/workspaces/${localWorkspaceFolderBasename}/.devcontainer/scripts/nats_stream.sh"
|
||||
}
|
||||
55
.devcontainer/docker-compose.yml
Normal file
55
.devcontainer/docker-compose.yml
Normal file
@@ -0,0 +1,55 @@
|
||||
version: "3.9"
|
||||
|
||||
networks:
|
||||
default:
|
||||
|
||||
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
# Overrides default command so things don't shut down after the process ends.
|
||||
command: sleep infinity
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- ../..:/workspaces:cached
|
||||
- ./nsc:/nsc
|
||||
networks:
|
||||
- default
|
||||
# uncomment to use local SSH keys for dev container access
|
||||
#- type: bind
|
||||
# source: ~/.ssh/authorized_keys
|
||||
# target: /home/vscode/.ssh/authorized_keys
|
||||
# read_only: true
|
||||
# depends_on:
|
||||
# - nats
|
||||
# Use "forwardPorts" in **devcontainer.json** to forward a port locally.
|
||||
|
||||
# nats-init:
|
||||
# image: natsio/nats-box
|
||||
# environment:
|
||||
# - NSC_HOME=/nsc
|
||||
# volumes:
|
||||
# - ./nsc:/nsc
|
||||
# - ./nats:/nats
|
||||
# - ./scripts:/scripts
|
||||
# networks:
|
||||
# - default
|
||||
# command:
|
||||
# - /scripts/nats_init.sh
|
||||
|
||||
# nats:
|
||||
# image: "nats:alpine"
|
||||
# depends_on:
|
||||
# - nats-init
|
||||
# command:
|
||||
# - -c
|
||||
# - "/etc/nats/nats-server.conf"
|
||||
# - -D
|
||||
# volumes:
|
||||
# - ./nats/:/etc/nats
|
||||
# networks:
|
||||
# - default
|
||||
# restart: unless-stopped
|
||||
32
.devcontainer/nats/nats-server.conf
Normal file
32
.devcontainer/nats/nats-server.conf
Normal file
@@ -0,0 +1,32 @@
|
||||
server_name: nats
|
||||
|
||||
# Client port of 4222 on all interfaces
|
||||
port: 4222
|
||||
|
||||
# HTTP monitoring port
|
||||
monitor_port: 8222
|
||||
|
||||
# # This is for clustering multiple servers together.
|
||||
# cluster {
|
||||
# name: "cluster1"
|
||||
# listen: 0.0.0.0:6222
|
||||
# routes = [nats://127.0.0.1:6222]
|
||||
# cluster_advertise: nats-server:6222
|
||||
# connect_retries: 0
|
||||
# }
|
||||
|
||||
jetstream: enabled
|
||||
jetstream {
|
||||
store_dir: /data/jetstream
|
||||
max_mem: 10M
|
||||
max_file: 1G
|
||||
}
|
||||
|
||||
debug: true
|
||||
logtime: true
|
||||
|
||||
max_payload: 4MB
|
||||
lame_duck_grace_period: 10s
|
||||
lame_duck_duration: 30s
|
||||
|
||||
include "resolver.conf"
|
||||
13
.devcontainer/scripts/nats_account.sh
Executable file
13
.devcontainer/scripts/nats_account.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
DIR="$( dirname -- "${BASH_SOURCE[0]}"; )";
|
||||
echo "DIR IS $DIR"
|
||||
DEVCONTAINER_DIR="$DIR/.."
|
||||
|
||||
sudo chown -Rh $USER:$USER $DEVCONTAINER_DIR/nsc
|
||||
|
||||
echo "Dumping NATS user creds file"
|
||||
nsc --data-dir=$DEVCONTAINER_DIR/nsc/nats/nsc/stores generate creds -a LBAAS -n USER > /tmp/user.creds
|
||||
|
||||
echo "Dumping NATS sys creds file"
|
||||
nsc --data-dir=$DEVCONTAINER_DIR/nsc/nats/nsc/stores generate creds -a SYS -n sys > /tmp/sys.creds
|
||||
32
.devcontainer/scripts/nats_init.sh
Executable file
32
.devcontainer/scripts/nats_init.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
# script to bootstrap a nats operator environment
|
||||
|
||||
if nsc describe operator; then
|
||||
echo "operator exists, not overwriting config"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Cleaning up NATS environment"
|
||||
rm -rf /nsc/*
|
||||
|
||||
echo "Creating NATS operator"
|
||||
nsc add operator --generate-signing-key --sys --name LOCAL
|
||||
nsc edit operator -u 'nats://nats:4222'
|
||||
nsc list operators
|
||||
nsc describe operator
|
||||
|
||||
export OPERATOR_SIGNING_KEY_ID=`nsc describe operator -J | jq -r '.nats.signing_keys | first'`
|
||||
|
||||
echo "Creating NATS account for load-balancer-api"
|
||||
nsc add account -n LBAAS -K ${OPERATOR_SIGNING_KEY_ID}
|
||||
nsc edit account LBAAS --sk generate --js-mem-storage -1 --js-disk-storage -1 --js-streams -1 --js-consumer -1
|
||||
nsc describe account LBAAS
|
||||
|
||||
export ACCOUNTS_SIGNING_KEY_ID=`nsc describe account LBAAS -J | jq -r '.nats.signing_keys | first'`
|
||||
|
||||
echo "Creating NATS user for load-balancer-api"
|
||||
nsc add user -n USER -K ${ACCOUNTS_SIGNING_KEY_ID}
|
||||
nsc describe user USER
|
||||
|
||||
echo "Generating NATS resolver.conf"
|
||||
nsc generate config --mem-resolver --sys-account SYS --config-file /nats/resolver.conf --force
|
||||
35
.devcontainer/scripts/nats_stream.sh
Executable file
35
.devcontainer/scripts/nats_stream.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
# script to bootstrap a nats stream
|
||||
|
||||
create_stream(){
|
||||
local name subject
|
||||
name="$1"; shift
|
||||
subject="$1"; shift
|
||||
|
||||
if nats stream ls | grep -q "$name" 2>/dev/null; then
|
||||
echo "stream $name already exists" >&2
|
||||
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Creating stream $name" >&2
|
||||
|
||||
nats stream add "$name" \
|
||||
--subjects "$subject" \
|
||||
--storage memory \
|
||||
--replicas 1 \
|
||||
--retention limits \
|
||||
--discard old \
|
||||
--max-msgs=-1 \
|
||||
--max-msgs-per-subject=-1 \
|
||||
--max-bytes=-1 \
|
||||
--max-age=-1 \
|
||||
--max-msg-size=-1 \
|
||||
--dupe-window 2m0s \
|
||||
--no-allow-rollup \
|
||||
--no-deny-delete \
|
||||
--no-deny-purge $@
|
||||
}
|
||||
|
||||
create_stream com-infratographer 'com.infratographer.>'
|
||||
create_stream com-equinixmetal 'com.equinixmetal.>'
|
||||
Reference in New Issue
Block a user