Skip to content

Commit 4732907

Browse files
author
James Belchamber
committed
Rewriting GCP as a Terraform module, updating packages and adding workflows and a devcontainer
1 parent ce48f82 commit 4732907

27 files changed

+711
-751
lines changed

.devcontainer/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Dockerfile
2+
FROM docker.io/golang:latest
3+
4+
RUN apt-get update &&\
5+
apt-get upgrade -y &&\
6+
apt-get install -y apt-transport-https &&\
7+
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg &&\
8+
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list &&\
9+
apt-get update &&\
10+
apt-get install google-cloud-cli -y &&\
11+
apt-get clean
12+
13+
RUN curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh &&\
14+
chmod +x install-opentofu.sh &&\
15+
./install-opentofu.sh --install-method deb &&\
16+
rm -f install-opentofu.sh &&\
17+
apt-get clean
18+
19+
RUN mkdir -p /usr/local/bin && apt-get update && apt-get install -y unzip && curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
20+
21+
RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin

.devcontainer/devcontainer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "Juicebox Software Realm",
3+
"dockerFile": "Dockerfile",
4+
"features": {
5+
"ghcr.io/devcontainers-extra/features/pre-commit:2": {},
6+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
7+
"ghcr.io/devcontainers/features/common-utils": {
8+
"installZsh": true,
9+
"installOhMyZsh": true,
10+
"installOhMyZshConfig": true,
11+
"configureZshAsDefaultShell": true,
12+
"upgradePackages": true
13+
}
14+
},
15+
"postCreateCommand": "bash .devcontainer/post-create.sh"
16+
}

.devcontainer/post-create.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# Install pre-commit hooks
4+
pre-commit install
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build and Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
build_and_publish:
14+
name: Build and Publish
15+
runs-on: ubuntu-latest
16+
17+
permissions:
18+
contents: read
19+
packages: write
20+
attestations: write
21+
id-token: write
22+
23+
steps:
24+
- name: Checkout Code
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Go
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version: "1.24.4"
31+
check-latest: false
32+
33+
- name: Build Executable
34+
run: |
35+
go build ./cmd/jb-sw-realm
36+
37+
- name: Login to GitHub Container Registry
38+
uses: docker/login-action@v3
39+
with:
40+
registry: ${{ env.REGISTRY }}
41+
username: ${{ github.actor }}
42+
password: ${{ secrets.GITHUB_TOKEN }}
43+
44+
- name: Extract metadata (tags, labels) for Docker
45+
id: meta
46+
uses: docker/metadata-action@v5
47+
with:
48+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
49+
50+
- name: Build and push Docker image
51+
id: push
52+
uses: docker/build-push-action@v6
53+
with:
54+
context: .
55+
push: true
56+
tags: ${{ steps.meta.outputs.tags }}
57+
labels: ${{ steps.meta.outputs.labels }}
58+
59+
- name: Generate artifact attestation
60+
uses: actions/attest-build-provenance@v2
61+
with:
62+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
63+
subject-digest: ${{ steps.push.outputs.digest }}
64+
push-to-registry: true
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
name: CI
1+
name: Lint and Test
22

33
on:
44
pull_request: {}
5-
push:
6-
branches:
7-
- main
85
workflow_dispatch: {}
96

107
jobs:
@@ -13,18 +10,18 @@ jobs:
1310
runs-on: ubuntu-latest
1411
steps:
1512
- name: Checkout Code
16-
uses: actions/checkout@v3
13+
uses: actions/checkout@v4
1714

1815
- name: Set up Go
19-
uses: actions/setup-go@v3
16+
uses: actions/setup-go@v5
2017
with:
21-
go-version: '1.22.2'
18+
go-version: "1.24.4"
2219
check-latest: false
2320

2421
- name: Run revive
2522
run: |
2623
go install github.com/mgechev/revive@latest
27-
revive -config revive.toml -formatter friendly -set_exit_status ./...
24+
revive -config revive.toml -formatter friendly ./...
2825
2926
- name: Run staticcheck
3027
run: |

.pre-commit-config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: end-of-file-fixer
6+
- id: trailing-whitespace
7+
- id: check-case-conflict
8+
- id: check-merge-conflict
9+
- id: detect-private-key
10+
- repo: https://github.com/antonbabenko/pre-commit-terraform
11+
rev: v1.99.3
12+
hooks:
13+
- id: terraform_fmt
14+
- id: terraform_validate
15+
- id: terraform_tflint
16+
- id: terraform_trivy

Dockerfile

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,13 @@
1-
FROM golang:1.22.2 as build-env
1+
FROM debian:latest
22

3-
WORKDIR /app
3+
RUN apt update && apt install -y ca-certificates
44

5-
COPY go.mod go.sum ./
6-
7-
RUN go mod download
8-
9-
COPY . .
10-
11-
RUN CGO_ENABLED=0 go build -o /jb-sw-realm ./cmd/jb-sw-realm
12-
13-
FROM debian:11-slim
14-
15-
RUN apt-get update && apt-get install -y curl supervisor
16-
17-
WORKDIR /otel
18-
19-
RUN curl -LO https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.77.0/otelcol-contrib_0.77.0_linux_amd64.tar.gz \
20-
&& tar -xzvf otelcol-contrib_0.77.0_linux_amd64.tar.gz \
21-
&& mv otelcol-contrib /usr/local/bin/otelcol-contrib \
22-
&& rm -rf /otel
23-
24-
COPY otel-collector-config.yaml /etc/otelcol-contrib/config.yaml
25-
26-
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
27-
28-
COPY --from=build-env /jb-sw-realm /usr/local/bin/jb-sw-realm
5+
COPY jb-sw-realm /usr/local/bin/jb-sw-realm
296

307
ENV PORT 8080
318

329
EXPOSE 8080
3310

3411
HEALTHCHECK CMD curl --fail "http://localhost:8080" || exit 1
3512

36-
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
13+
ENTRYPOINT ["/usr/local/bin/jb-sw-realm"]

README.md

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -76,48 +76,26 @@ The realm software will determine which tenant key to validate on a request by a
7676

7777
## GCP
7878

79-
The following instructions will help you quickly deploy a realm to Google's App Engine Flex.
80-
81-
Before you begin, setup a project for your realm to run in on [console.cloud.google.com](https://console.cloud.google.com) and make note of its ID.
82-
83-
Next, setup your project environment with terraform as follows:
84-
```sh
85-
cd gcp
86-
terraform init
87-
terraform plan -var='tenant_secrets={"acme":"acme-tenant-key","anotherTenant":"another-tenant-key"}'
88-
terraform apply -var='tenant_secrets={"acme":"acme-tenant-key","anotherTenant":"another-tenant-key"}'
89-
```
90-
91-
Note: you should update the tenant secrets `var` to reflect the actual secrets you wish to support.
92-
93-
After terraform has finished configuring your project environment, you should see an output like follows:
94-
```sh
95-
BIGTABLE_INSTANCE_ID = "jb-sw-realms"
96-
GCP_PROJECT_ID = "your-project-id"
97-
REALM_ID = "99b2da84-b707-6203-dc35-804bbbcb8cba"
98-
SERVICE_ACCOUNT = "[email protected]"
99-
```
100-
101-
Open the `cmd/jb-sw-realm/app.yaml` file and configure it with these values where appropriate, for example:
102-
Replace `{{YOUR_BIGTABLE_INSTANCE_ID}}` with `jb-sw-realms`.
103-
104-
Finally, you can deploy the realm software by running the following command from the `cmd/jb-sw-realm` directory of the repo:
105-
```sh
106-
gcloud app deploy --project {{YOUR_GCP_PROJECT_ID}}
107-
```
108-
109-
Note: you will need to have the `gcloud` command line tools installed to execute this command. You can find instructions on installing these [here](https://cloud.google.com/sdk/docs/install).
110-
111-
This may take a few minutes, but upon success you should be able to access your realm at:
112-
https://{{YOUR_GCP_PROJECT_ID}}.wl.r.appspot.com
113-
114-
If all was successful, you'll see a page render that looks something like:
115-
```json
116-
{"realmID":"99b2da84-b707-6203-dc35-804bbbcb8cba"}
79+
The `gcp/` directory is now a Terraform module which can be leveraged in your own Terraform codebase. For example:
80+
81+
```terraform
82+
module "juicebox-software-realm" {
83+
source = "github.com/rpcpool/juicebox-software-realm.git//gcp"
84+
85+
project_id = "your-project-id"
86+
realm_id = "99b2da84b7076203dc35804bbbcb8cba"
87+
region = "europe-west3"
88+
zone = "c"
89+
tenant_secrets = {"acme":"acme-tenant-key","anotherTenant":"another-tenant-key"}
90+
juicebox_image_url = "path/to/juicebox/container/image"
91+
juicebox_image_version = "latest"
92+
otelcol_image_url = "path/to/otel/collector/container/image"
93+
otelcol_image_version = "latest"
94+
otelcol_config_b64 = filebase64("otel-collector-config.yaml")
95+
}
11796
```
11897

119-
If you wish to configure a custom domain for your new realm, visit:
120-
https://console.cloud.google.com/appengine/settings/domains
98+
This will deploy an instance of Juicebox Software Realm along with the necessary infrastructure that supports it. Please note that you will either need to deploy the Juicebox and OpenTelemetry Collector containers to a repository in GCP, or else use a remote repository which caches them from GitHub.
12199

122100
## AWS
123101

cmd/jb-sw-realm/app.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.

gcp/.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ crash.log
1010
crash.*.log
1111

1212
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
13-
# password, private keys, and other secrets. These should not be part of version
14-
# control as they are data points which are potentially sensitive and subject
13+
# password, private keys, and other secrets. These should not be part of version
14+
# control as they are data points which are potentially sensitive and subject
1515
# to change depending on the environment.
1616
*.tfvars
1717
*.tfvars.json
@@ -32,3 +32,6 @@ override.tf.json
3232
# Ignore CLI configuration files
3333
.terraformrc
3434
terraform.rc
35+
36+
# This is a module, so ignore .lock.hcl
37+
.terraform.lock.hcl

0 commit comments

Comments
 (0)