Skip to content

Commit c1ca1b9

Browse files
committed
initial commit
1 parent 10735ef commit c1ca1b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3800
-3
lines changed

.dockerignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# .dockerignore
2+
3+
.git
4+
.history
5+
.vscode
6+
*.bak
7+
*.swp
8+
.DS_Store
9+
10+
private
11+
service/service
12+
test-client/test-client

.github/workflows/create_release.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Create Release
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Build Image"]
6+
types:
7+
- completed
8+
push:
9+
tags: ["v*.*.*"]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Create Release
21+
uses: ncipollo/release-action@v1
22+
with:
23+
generateReleaseNotes: true
24+
allowUpdates: true

.github/workflows/docker_image.yml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Build Image
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
push:
10+
# branches: ["main"]
11+
# Publish semver tags as releases.
12+
tags: ["v*.*.*"]
13+
# pull_request:
14+
# branches: ["main"]
15+
16+
env:
17+
# Use docker.io for Docker Hub if empty
18+
REGISTRY: ghcr.io
19+
# github.repository as <account>/<repo>
20+
IMAGE_NAME: ${{ github.repository }}
21+
22+
jobs:
23+
build:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
packages: write
28+
# This is used to complete the identity challenge
29+
# with sigstore/fulcio when running outside of PRs.
30+
id-token: write
31+
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v4
35+
36+
# Install the cosign tool except on PR
37+
# https://github.com/sigstore/cosign-installer
38+
- name: Install cosign
39+
if: github.event_name != 'pull_request'
40+
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
41+
with:
42+
cosign-release: "v2.2.4"
43+
44+
# Set up BuildKit Docker container builder to be able to build
45+
# multi-platform images and export cache
46+
# https://github.com/docker/setup-buildx-action
47+
- name: Set up Docker Buildx
48+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
49+
50+
# Login against a Docker registry except on PR
51+
# https://github.com/docker/login-action
52+
- name: Log into registry ${{ env.REGISTRY }}
53+
if: github.event_name != 'pull_request'
54+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
55+
with:
56+
registry: ${{ env.REGISTRY }}
57+
username: ${{ github.actor }}
58+
password: ${{ secrets.GITHUB_TOKEN }}
59+
60+
# Extract metadata (tags, labels) for Docker
61+
# https://github.com/docker/metadata-action
62+
- name: Extract Docker metadata
63+
id: meta
64+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
65+
with:
66+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
67+
68+
# Build and push Docker image with Buildx (don't push on PR)
69+
# https://github.com/docker/build-push-action
70+
- name: Build and push Docker image
71+
id: build-and-push
72+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
73+
with:
74+
context: .
75+
push: ${{ github.event_name != 'pull_request' }}
76+
tags: ${{ steps.meta.outputs.tags }}
77+
labels: ${{ steps.meta.outputs.labels }}
78+
cache-from: type=gha
79+
cache-to: type=gha,mode=max
80+
build-args: |
81+
GOOS=${{ matrix.os }}
82+
GOARCH=${{ matrix.architecture }}
83+
84+
# Sign the resulting Docker image digest except on PRs.
85+
# This will only write to the public Rekor transparency log when the Docker
86+
# repository is public to avoid leaking data. If you would like to publish
87+
# transparency data even for private images, pass --force to cosign below.
88+
# https://github.com/sigstore/cosign
89+
- name: Sign the published Docker image
90+
if: ${{ github.event_name != 'pull_request' }}
91+
env:
92+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
93+
TAGS: ${{ steps.meta.outputs.tags }}
94+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
95+
# This step uses the identity token to provision an ephemeral certificate
96+
# against the sigstore community Fulcio instance.
97+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

.gitignore

+17-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,29 @@
1111
# Test binary, built with `go test -c`
1212
*.test
1313

14+
# Application binaries
15+
service/service
16+
test-client/test-client
17+
1418
# Output of the go coverage tool, specifically when used with LiteIDE
1519
*.out
1620

1721
# Dependency directories (remove the comment below to include it)
18-
# vendor/
22+
vendor/
1923

2024
# Go workspace file
2125
go.work
2226
go.work.sum
2327

24-
# env file
25-
.env
28+
# Mac OS X files
29+
.DS_Store
30+
31+
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
32+
.glide/
33+
34+
# Other
35+
.history/
36+
37+
private/
38+
build/
39+
dist/

Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ARG GOVERSION=1.22
2+
3+
FROM golang:${GOVERSION}-alpine
4+
LABEL org.opencontainers.image.source "https://github.com/jr200/nats-iam-broker"
5+
LABEL org.opencontainers.image.description "nats-iam-broker alpine image"
6+
7+
ARG GOARCH
8+
ARG GOOS
9+
10+
RUN echo nats-iam-broker-${GOOS}-${GOARCH}
11+
12+
RUN apk update && apk add git bash curl jq make
13+
RUN go install github.com/nats-io/nats-server/[email protected]
14+
RUN go install github.com/nats-io/natscli/[email protected]
15+
RUN go install github.com/nats-io/nsc/[email protected]
16+
17+
# RUN curl -L https://github.com/openbao/openbao/releases/download/v2.0.0/bao_2.0.0_Linux_x86_64.tar.gz | tar xz -C /usr/local/bin bao
18+
19+
WORKDIR /usr/src/app
20+
21+
COPY . .
22+
23+
RUN make build && \
24+
ln build/nats-iam-broker-${GOOS}-${GOARCH} /usr/local/bin/nats-iam-broker && \
25+
ln build/test-client-${GOOS}-${GOARCH} /usr/local/bin/test-client
26+
27+
ENTRYPOINT ["bash"]

Makefile

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# get target architecture
2+
LOCAL_ARCH := $(shell uname -m)
3+
ifeq ($(LOCAL_ARCH),x86_64)
4+
TARGET_ARCH_LOCAL=amd64
5+
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),armv8)
6+
TARGET_ARCH_LOCAL=arm64
7+
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 4),armv)
8+
TARGET_ARCH_LOCAL=arm
9+
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),arm64)
10+
TARGET_ARCH_LOCAL=arm64
11+
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 7),aarch64)
12+
TARGET_ARCH_LOCAL=arm64
13+
else
14+
TARGET_ARCH_LOCAL=amd64
15+
endif
16+
export GOARCH ?= $(TARGET_ARCH_LOCAL)
17+
18+
# get docker tag
19+
ifeq ($(GOARCH),amd64)
20+
LATEST_TAG?=latest
21+
else
22+
LATEST_TAG?=latest-$(GOARCH)
23+
endif
24+
25+
# get target os
26+
LOCAL_OS := $(shell uname -s)
27+
ifeq ($(LOCAL_OS),Linux)
28+
TARGET_OS_LOCAL = linux
29+
else ifeq ($(LOCAL_OS),Darwin)
30+
TARGET_OS_LOCAL = darwin
31+
PATH := $(PATH):$(HOME)/go/bin/darwin_$(GOARCH)
32+
else
33+
echo "Not Supported"
34+
TARGET_OS_LOCAL = windows
35+
endif
36+
export GOOS ?= $(TARGET_OS_LOCAL)
37+
38+
# Default docker container and e2e test target.
39+
TARGET_OS ?= linux
40+
TARGET_ARCH ?= amd64
41+
42+
OUT_DIR := ./dist
43+
44+
.DEFAULT_GOAL := all
45+
46+
DOCKER_REGISTRY ?= ghcr.io/jr200
47+
IMAGE_NAME ?= nats-iam-broker
48+
49+
50+
################################################################################
51+
# Target: all #
52+
################################################################################
53+
.PHONY: all
54+
all: fmt build
55+
56+
################################################################################
57+
# Target: fmt #
58+
################################################################################
59+
.PHONY: fmt
60+
fmt:
61+
go fmt $$(go list ./...)
62+
63+
################################################################################
64+
# Target: build #
65+
################################################################################
66+
.PHONY: build
67+
build:
68+
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) \
69+
go build -o build/nats-iam-broker-$(GOOS)-$(GOARCH) -gcflags "all=-N -l" -ldflags '-extldflags "-static"' \
70+
cmd/nats-iam-broker/main.go
71+
72+
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) \
73+
go build -o build/test-client-$(GOOS)-$(GOARCH) -gcflags "all=-N -l" -ldflags '-extldflags "-static"' \
74+
cmd/test-client/main.go
75+
76+
77+
################################################################################
78+
# Target: docker-build-example #
79+
################################################################################
80+
.PHONY: docker-build-example
81+
docker-build-example:
82+
docker build \
83+
-f Dockerfile \
84+
--build-arg GOOS=linux --build-arg GOARCH=amd64 \
85+
-t nats-iam-broker:debug \
86+
.
87+
88+
################################################################################
89+
# Target: example-shell #
90+
################################################################################
91+
.PHONY: example-shell
92+
example-shell: docker-build-example
93+
docker run --rm -it --entrypoint bash nats-iam-broker:debug
94+
95+
################################################################################
96+
# Target: example-basic #
97+
################################################################################
98+
.PHONY: example-basic
99+
example-basic: docker-build-example
100+
docker run --rm --entrypoint examples/basic/run.sh nats-iam-broker:debug -log-human -log=info
101+
102+
################################################################################
103+
# Target: example-rgb_org #
104+
################################################################################
105+
.PHONY: example-rgb_org
106+
example-rgb_org: docker-build-example
107+
docker run --rm --entrypoint examples/rgb_org/run.sh nats-iam-broker:debug -log-human -log=info

0 commit comments

Comments
 (0)