-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
879 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,16 @@ RUN export DEBIAN_FRONTEND=noninteractive \ | |
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 | ||
|
||
RUN go install ariga.io/atlas/cmd/atlas@latest | ||
ENV NATS_CLI_VERSION=0.0.35 | ||
RUN go install -v github.com/cweill/gotests/[email protected] \ | ||
&& go install github.com/nats-io/natscli/nats@v${NATS_CLI_VERSION} \ | ||
&& go install github.com/nats-io/nkeys/nk@latest | ||
|
||
USER root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
.devcontainer/scripts/nats_account.sh | ||
|
||
sleep infinity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# 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 location-api" | ||
nsc add account -n LOC -K ${OPERATOR_SIGNING_KEY_ID} | ||
nsc edit account LOC --sk generate --js-mem-storage -1 --js-disk-storage -1 --js-streams -1 --js-consumer -1 | ||
nsc describe account LOC | ||
|
||
export ACCOUNTS_SIGNING_KEY_ID=`nsc describe account LOC -J | jq -r '.nats.signing_keys | first'` | ||
|
||
echo "Creating NATS user for location-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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
all: lint tests binary ## Runs lint, tests, and builds the binary | ||
|
||
PHONY: help all test coverage lint golint clean vendor docker-up docker-down unit-test | ||
GOOS=linux | ||
DB=location_api | ||
DEV_DB=${DB}_dev | ||
TEST_DB=${DB}_test | ||
DEV_URI="postgresql://root@crdb:26257/${DEV_DB}?sslmode=disable" | ||
TEST_URI="postgresql://root@crdb:26257/${TEST_DB}?sslmode=disable" | ||
|
||
APP_NAME=location-api | ||
PID_FILE=/tmp/loc.pid | ||
|
||
help: Makefile ## Print help | ||
@grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -e 's/:.*##/#/' | column -c 2 -t -s# | ||
|
||
tests: | unit-tests | ||
|
||
unit-tests: ## Runs unit tests | ||
@echo --- Running unit tests... | ||
@date --rfc-3339=seconds | ||
@go test -race -cover -failfast -tags testtools -p 1 -v ./... | ||
|
||
coverage: ## Generates coverage report | ||
@echo --- Generating coverage report... | ||
@date --rfc-3339=seconds | ||
@go test -race -coverprofile=coverage.out -covermode=atomic -tags testtools -p 1 ./... | ||
@go tool cover -func=coverage.out | ||
@go tool cover -html=coverage.out | ||
|
||
lint: golint ## Runs linting | ||
|
||
golint: | ||
@echo --- Running golint... | ||
@date --rfc-3339=seconds | ||
@golangci-lint run | ||
|
||
clean: ## Clean up all the things | ||
@echo --- Cleaning... | ||
@date --rfc-3339=seconds | ||
@rm -rf ./bin/ | ||
@rm -rf coverage.out | ||
@go clean -testcache | ||
|
||
binary: | vendor generate ## Builds the binary | ||
@echo --- Building binary... | ||
@date --rfc-3339=seconds | ||
@go build -o bin/${APP_NAME} main.go | ||
|
||
vendor: ## Vendors dependencies | ||
@echo --- Downloading dependencies... | ||
@date --rfc-3339=seconds | ||
@go mod tidy | ||
@go mod download | ||
|
||
testclient:| background-run .testclient kill-running ## Regenerates the test client in graphclient | ||
|
||
.testclient: | ||
@echo --- Generating test graph client... | ||
@date --rfc-3339=seconds | ||
@go generate ./internal/graphclient | ||
|
||
dev-nats: ## Initializes nats | ||
@echo --- Initializing nats | ||
@date --rfc-3339=seconds | ||
@.devcontainer/scripts/nats_account.sh | ||
|
||
generate: background-run .generate kill-running ## Generates code | ||
|
||
.generate: | ||
@echo --- Generating code... | ||
@date --rfc-3339=seconds | ||
@go generate ./... | ||
|
||
go-run: ## Runs the app | ||
@echo --- Running binary... | ||
@date --rfc-3339=seconds | ||
@go run main.go serve --dev | ||
|
||
background-run: ## Runs in the app in the background | ||
@date --rfc-3339=seconds | ||
@if [ ! -f "${PID_FILE}" ]; then \ | ||
echo --- Running binary in the background...; \ | ||
go run main.go serve --dev --oidc=false --pid-file=${PID_FILE} & \ | ||
else \ | ||
echo --- Binary already running in the background...; \ | ||
fi | ||
|
||
kill-running: ## Kills the running binary from pid file | ||
@echo --- Killing background binary... | ||
@date --rfc-3339=seconds | ||
@kill $$(cat ${PID_FILE}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.