Skip to content

Commit

Permalink
Bumping versions, more devcontainer initialization (#36)
Browse files Browse the repository at this point in the history
* .devcontainer nats, env

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>

* align .github

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>

* bump go to 1.21, bump deps

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>

* generate test client

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>

* regenerate

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>

* bump common, reloader charts

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>

---------

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>
  • Loading branch information
rizzza authored Oct 19, 2023
1 parent a135cfb commit eafbd8c
Show file tree
Hide file tree
Showing 32 changed files with 367 additions and 171 deletions.
5 changes: 4 additions & 1 deletion .devcontainer/.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ COCKROACH_URL="postgresql://root@crdb:26257/resource_provider_api_dev?sslmode=di
# RESOURCEPROVIDERAPI config
ATLAS_DB_URI="postgresql://root@crdb:26257/atlas_migrations?sslmode=disable"
RESOURCEPROVIDER_CRDB_URI="postgresql://root@crdb:26257/resource_provider_api_dev?sslmode=disable"
RESOURCEPROVIDER_EVENTS_NATS_CREDSFILE="/workspaces/resource-provider-api/.devcontainer/nsc/nkeys/creds/LOCAL/META/USER.creds"
RESOURCEPROVIDER_EVENTS_NATS_PUBLISHPREFIX=com.infratographer

NKEYS_PATH="/workspaces/resource-provider-api/.devcontainer/nsc/nkeys"
NSC_HOME="/workspaces/resource-provider-api/.devcontainer/nsc/nats"

# postgresql client config
PGHOST=crdb
PGPORT=26257
PGSSLMODE=disable
PGDATABASE=resource_provider_api_dev
PGUSER=root
PAGER="less -iMx4 -FXe"
PAGER="less -iMx4 -FXe"
22 changes: 12 additions & 10 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
ARG GO_VERSION=1.21

# Used to install CRDB into the devcontainer
FROM cockroachdb/cockroach:latest-v22.2 as CRDB

FROM mcr.microsoft.com/vscode/devcontainers/go:1-1.20-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/go:1-${GO_VERSION}-bullseye

# Set up crdb
RUN mkdir /usr/local/lib/cockroach
Expand All @@ -22,17 +24,17 @@ 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
# 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
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 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
USER root
25 changes: 24 additions & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
context: .
dockerfile: Dockerfile
args:
VARIANT: 1.20-bullseye
VARIANT: 1.21-bullseye
NODE_VERSION: "none"
# Overrides default command so things don't shut down after the process ends.
command: sleep infinity
Expand Down Expand Up @@ -51,3 +51,26 @@ services:
retries: 3
start_period: "15s"
timeout: "5s"

nats-init:
image: natsio/nats-box
environment:
- NSC_HOME=/nsc
volumes:
- ./nsc:/nsc
- ./nats:/nats
- ./scripts:/scripts
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
restart: unless-stopped
32 changes: 32 additions & 0 deletions .devcontainer/nats/nats-server.conf
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"
7 changes: 7 additions & 0 deletions .devcontainer/scripts/app-entrypoint.sh
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
35 changes: 35 additions & 0 deletions .devcontainer/scripts/nats_init.sh
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 resource-provider-api"
nsc add account -n RESP -K ${OPERATOR_SIGNING_KEY_ID}
nsc edit account RESP --sk generate --js-mem-storage -1 --js-disk-storage -1 --js-streams -1 --js-consumer -1
nsc describe account RESP

export ACCOUNTS_SIGNING_KEY_ID=`nsc describe account RESP -J | jq -r '.nats.signing_keys | first'`

echo "Creating NATS user for resource-provider-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
4 changes: 2 additions & 2 deletions .github/workflows/image-main-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
go-version-file: go.mod

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
Expand All @@ -35,4 +35,4 @@ jobs:
args: release --nightly --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
4 changes: 1 addition & 3 deletions .github/workflows/lint-go.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Lint - Go
on:
push:
branches:
- main
pull_request:
permissions:
contents: read
Expand All @@ -20,4 +18,4 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
args: --timeout=5m
version: latest
version: latest
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- run: git fetch --force --tags

Expand All @@ -51,4 +51,4 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
10 changes: 4 additions & 6 deletions .github/workflows/test-go.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
name: Test - Golang

# Run for all pushes to main and pull requests when Go or YAML files change
on:
push:
branches:
- main
pull_request:

jobs:
gotest:
name: test
Expand Down Expand Up @@ -38,11 +38,9 @@ jobs:
- name: Set up Go for ${{ matrix.ci-database }}
uses: actions/setup-go@v4
with:
#pinning to 1.20.5 until https://github.com/testcontainers/testcontainers-go/issues/1359 is resolved
#go-version-file: "go.mod"
go-version: "1.20.5"
go-version-file: "go.mod"
- name: Install atlas for db migrations on ${{ matrix.ci-database }}
run: go install ariga.io/atlas/cmd/atlas@latest

- name: Run go tests for ${{ matrix.ci-database }}
run: RESOURCEPROVIDERAPI_TESTDB_URI="${{ matrix.env-database-uri }}" go test -race -coverprofile=coverage.txt -covermode=atomic -tags testtools ./...
run: RESOURCEPROVIDERAPI_TESTDB_URI="${{ matrix.env-database-uri }}" go test -race -coverprofile=coverage.txt -covermode=atomic -tags testtools ./...
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

# build artifacts
bin/

# devcontainer artifacts
.devcontainer/nats/resolver.conf
.devcontainer/nsc

# Go workspace file
go.work

# Cover file
coverage.txt

# vscode
.vscode
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ vendor: ## Vendors dependencies
@go mod tidy
@go mod download


dev-nats: ## Initializes nats
@echo --- Initializing nats
@date --rfc-3339=seconds
Expand All @@ -68,3 +67,13 @@ 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
@echo --- Running binary in the background...
@date --rfc-3339=seconds
@go run main.go serve --pid-file=${PID_FILE} --oidc=false &

kill-running: ## Kills the running binary from pid file
@echo --- Killing background binary...
@date --rfc-3339=seconds
@kill $$(cat ${PID_FILE})
8 changes: 4 additions & 4 deletions chart/resource-provider-api/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
dependencies:
- name: common
repository: https://charts.bitnami.com/bitnami
version: 2.4.0
version: 2.13.3
- name: reloader
repository: https://stakater.github.io/stakater-charts
version: v1.0.26
digest: sha256:3c3375ee126dbeb45635c24e7810c06d1f5f77ffabefd21c94d9822d8ec88660
generated: "2023-07-27T13:04:02.420252-04:00"
version: 1.0.44
digest: sha256:55346e2ff2ccd1d67e6a57784d9e5aa5cd15dac5aecbb32112daf66c7de88f5d
generated: "2023-10-18T23:37:47.165852064Z"
6 changes: 3 additions & 3 deletions chart/resource-provider-api/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ dependencies:
repository: https://charts.bitnami.com/bitnami
tags:
- bitnami-common
version: 2.4.0
version: 2.13.3
- name: reloader
condition: reloader.enabled
version: "v1.0.26"
repository: "https://stakater.github.io/stakater-charts"
version: "v1.0.44"
repository: "https://stakater.github.io/stakater-charts"
Binary file not shown.
Binary file removed chart/resource-provider-api/charts/common-2.4.0.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit eafbd8c

Please sign in to comment.