Skip to content
This repository was archived by the owner on Jul 9, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 138 additions & 138 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,141 +88,141 @@ jobs:
dockerfile: ${{ matrix.dockerfile }}
context: ${{ matrix.context }}

deploy:
needs: [gate, build]
if: needs.gate.outputs.should_deploy == 'true'
runs-on: ubuntu-24.04
permissions:
contents: read
pull-requests: write
env:
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
steps:
- uses: actions/checkout@v5

- name: Compute image tag
run: |
REF_NAME=$(echo '${{ github.ref_name }}' | tr '/' '-')
echo "IMAGE_TAG=${{ github.sha }}-${REF_NAME}-${{ github.run_number }}" >> $GITHUB_ENV

- name: Clone Flux repo
run: |
git clone --depth 1 "https://oauth2:${{ secrets.GITLAB_TOKEN }}@${{ vars.GITLAB_REPO_HOST }}/${{ vars.GITLAB_REPO_PATH }}.git" flux-repo
cd flux-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Generate PR overlay
run: |
PR_DIR="flux-repo/apps/dcim/overlays/pr/pr-${PR_NUMBER}"
mkdir -p "$PR_DIR"

export PR_NUM="$PR_NUMBER"
export PR_BRANCH="$PR_BRANCH"
export DOMAIN="$DOMAIN"
export IMAGE_PREFIX="$IMAGE_PREFIX"
export IMAGE_TAG="$IMAGE_TAG"

envsubst '${PR_NUM} ${PR_BRANCH} ${DOMAIN} ${IMAGE_PREFIX} ${IMAGE_TAG}' \
< charts/dcim/pr-overlay.yaml \
> "$PR_DIR/resources.yaml"

- name: Update kustomization.yaml
run: |
cd flux-repo
KUSTOMIZATION="apps/dcim/overlays/pr/kustomization.yaml"

# Create base kustomization if it doesn't exist
if [ ! -f "$KUSTOMIZATION" ]; then
mkdir -p "$(dirname "$KUSTOMIZATION")"
cat > "$KUSTOMIZATION" << 'EOF'
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
EOF
fi

# Add PR resource entry if not already present
PR_ENTRY="pr-${PR_NUMBER}/resources.yaml"
if ! grep -q "$PR_ENTRY" "$KUSTOMIZATION"; then
echo " - $PR_ENTRY" >> "$KUSTOMIZATION"
fi

- name: Commit and push
run: |
cd flux-repo
git add -A
if git diff --cached --quiet; then
echo "No changes to commit"
else
git commit -m "deploy: PR #${PR_NUMBER} environment

Commit: ${IMAGE_TAG}
Branch: ${PR_BRANCH}"
git push
fi

- name: Post PR comment
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-environment
message: |
## PR Environment

| Service | URL |
|---------|-----|
| Console | https://console.pr${{ env.PR_NUMBER }}.${{ env.DOMAIN }} |
| API | https://api.pr${{ env.PR_NUMBER }}.${{ env.DOMAIN }} |

**Commit:** `${{ env.IMAGE_TAG }}`
**Namespace:** `tn-dcim-pr-${{ env.PR_NUMBER }}`

> Environment will be ready once Flux reconciles (~5 min after images are built).

teardown:
needs: gate
if: needs.gate.outputs.should_teardown == 'true'
runs-on: ubuntu-24.04
permissions:
pull-requests: write
steps:
- name: Clone Flux repo
run: |
git clone --depth 1 "https://oauth2:${{ secrets.GITLAB_TOKEN }}@${{ vars.GITLAB_REPO_HOST }}/${{ vars.GITLAB_REPO_PATH }}.git" flux-repo
cd flux-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Remove PR overlay
run: |
cd flux-repo
PR_DIR="apps/dcim/overlays/pr/pr-${PR_NUMBER}"

# Remove PR directory
rm -rf "$PR_DIR"

# Remove entry from kustomization.yaml
KUSTOMIZATION="apps/dcim/overlays/pr/kustomization.yaml"
if [ -f "$KUSTOMIZATION" ]; then
sed -i "\|pr-${PR_NUMBER}/resources.yaml|d" "$KUSTOMIZATION"
fi

- name: Commit and push
run: |
cd flux-repo
git add -A
if git diff --cached --quiet; then
echo "No changes to commit"
else
git commit -m "teardown: PR #${PR_NUMBER} environment"
git push
fi

- name: Update PR comment
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-environment
message: |
## PR Environment - Torn Down

The environment for this PR has been removed.
# deploy:
# needs: [gate, build]
# if: needs.gate.outputs.should_deploy == 'true'
# runs-on: ubuntu-24.04
# permissions:
# contents: read
# pull-requests: write
# env:
# PR_BRANCH: ${{ github.event.pull_request.head.ref }}
# steps:
# - uses: actions/checkout@v5
#
# - name: Compute image tag
# run: |
# REF_NAME=$(echo '${{ github.ref_name }}' | tr '/' '-')
# echo "IMAGE_TAG=${{ github.sha }}-${REF_NAME}-${{ github.run_number }}" >> $GITHUB_ENV
#
# - name: Clone Flux repo
# run: |
# git clone --depth 1 "https://oauth2:${{ secrets.GITLAB_TOKEN }}@${{ vars.GITLAB_REPO_HOST }}/${{ vars.GITLAB_REPO_PATH }}.git" flux-repo
# cd flux-repo
# git config user.name "github-actions[bot]"
# git config user.email "github-actions[bot]@users.noreply.github.com"
#
# - name: Generate PR overlay
# run: |
# PR_DIR="flux-repo/apps/dcim/overlays/pr/pr-${PR_NUMBER}"
# mkdir -p "$PR_DIR"
#
# export PR_NUM="$PR_NUMBER"
# export PR_BRANCH="$PR_BRANCH"
# export DOMAIN="$DOMAIN"
# export IMAGE_PREFIX="$IMAGE_PREFIX"
# export IMAGE_TAG="$IMAGE_TAG"
#
# envsubst '${PR_NUM} ${PR_BRANCH} ${DOMAIN} ${IMAGE_PREFIX} ${IMAGE_TAG}' \
# < charts/dcim/pr-overlay.yaml \
# > "$PR_DIR/resources.yaml"
#
# - name: Update kustomization.yaml
# run: |
# cd flux-repo
# KUSTOMIZATION="apps/dcim/overlays/pr/kustomization.yaml"
#
# # Create base kustomization if it doesn't exist
# if [ ! -f "$KUSTOMIZATION" ]; then
# mkdir -p "$(dirname "$KUSTOMIZATION")"
# cat > "$KUSTOMIZATION" << 'EOF'
# apiVersion: kustomize.config.k8s.io/v1beta1
# kind: Kustomization
# resources:
# EOF
# fi
#
# # Add PR resource entry if not already present
# PR_ENTRY="pr-${PR_NUMBER}/resources.yaml"
# if ! grep -q "$PR_ENTRY" "$KUSTOMIZATION"; then
# echo " - $PR_ENTRY" >> "$KUSTOMIZATION"
# fi
#
# - name: Commit and push
# run: |
# cd flux-repo
# git add -A
# if git diff --cached --quiet; then
# echo "No changes to commit"
# else
# git commit -m "deploy: PR #${PR_NUMBER} environment
#
# Commit: ${IMAGE_TAG}
# Branch: ${PR_BRANCH}"
# git push
# fi
#
# - name: Post PR comment
# uses: marocchino/sticky-pull-request-comment@v2
# with:
# header: pr-environment
# message: |
# ## PR Environment
#
# | Service | URL |
# |---------|-----|
# | Console | https://console.pr${{ env.PR_NUMBER }}.${{ env.DOMAIN }} |
# | API | https://api.pr${{ env.PR_NUMBER }}.${{ env.DOMAIN }} |
#
# **Commit:** `${{ env.IMAGE_TAG }}`
# **Namespace:** `tn-dcim-pr-${{ env.PR_NUMBER }}`
#
# > Environment will be ready once Flux reconciles (~5 min after images are built).

# teardown:
# needs: gate
# if: needs.gate.outputs.should_teardown == 'true'
# runs-on: ubuntu-24.04
# permissions:
# pull-requests: write
# steps:
# - name: Clone Flux repo
# run: |
# git clone --depth 1 "https://oauth2:${{ secrets.GITLAB_TOKEN }}@${{ vars.GITLAB_REPO_HOST }}/${{ vars.GITLAB_REPO_PATH }}.git" flux-repo
# cd flux-repo
# git config user.name "github-actions[bot]"
# git config user.email "github-actions[bot]@users.noreply.github.com"
#
# - name: Remove PR overlay
# run: |
# cd flux-repo
# PR_DIR="apps/dcim/overlays/pr/pr-${PR_NUMBER}"
#
# # Remove PR directory
# rm -rf "$PR_DIR"
#
# # Remove entry from kustomization.yaml
# KUSTOMIZATION="apps/dcim/overlays/pr/kustomization.yaml"
# if [ -f "$KUSTOMIZATION" ]; then
# sed -i "\|pr-${PR_NUMBER}/resources.yaml|d" "$KUSTOMIZATION"
# fi
#
# - name: Commit and push
# run: |
# cd flux-repo
# git add -A
# if git diff --cached --quiet; then
# echo "No changes to commit"
# else
# git commit -m "teardown: PR #${PR_NUMBER} environment"
# git push
# fi
#
# - name: Update PR comment
# uses: marocchino/sticky-pull-request-comment@v2
# with:
# header: pr-environment
# message: |
# ## PR Environment - Torn Down
#
# The environment for this PR has been removed.
2 changes: 1 addition & 1 deletion .gomod-age.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"age": "7d",
"ignore": ["buf.build/*"]
"ignore": ["buf.build/*", "github.com/fundament-oss/*"]
}
4 changes: 2 additions & 2 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download
COPY api/ ./api/
RUN CGO_ENABLED=0 go build ./api/cmd/api
RUN CGO_ENABLED=0 go build -o /build/bin/api ./api/cmd/api

FROM scratch
COPY --from=builder /build/api /
COPY --from=builder /build/bin/api /
ENTRYPOINT ["/api"]
5 changes: 3 additions & 2 deletions api/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
)

type config struct {
ListenAddr string `env:"LISTEN_ADDR" envDefault:":8080"`
LogLevel string `env:"LOG_LEVEL" envDefault:"info"`
DatabaseURL string `env:"DATABASE_URL,required"`
ListenAddr string `env:"LISTEN_ADDR" envDefault:":8080"`
LogLevel string `env:"LOG_LEVEL" envDefault:"info"`
}

func main() {
Expand Down
17 changes: 16 additions & 1 deletion api/pkg/dcim/server.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package dcim

import (
"context"
"log/slog"
"net/http"

"connectrpc.com/connect"
"connectrpc.com/grpcreflect"
"connectrpc.com/validate"
"github.com/fundament-oss/dcim/api/pkg/proto/gen/v1/dcimv1connect"
"github.com/fundament-oss/fundament/common/connectrecovery"
"github.com/svrana/go-connect-middleware/interceptors/logging"
)

type Server struct {
Expand All @@ -21,7 +25,18 @@ func New(logger *slog.Logger) *Server {

mux := http.NewServeMux()

interceptors := connect.WithInterceptors()
loggingInterceptor := logging.UnaryServerInterceptor(
logging.LoggerFunc(func(ctx context.Context, level logging.Level, msg string, fields ...any) {
logger.Log(ctx, slog.Level(level), msg, fields...)
}),
logging.WithLogOnEvents(logging.FinishCall),
)

interceptors := connect.WithInterceptors(
connectrecovery.NewInterceptor(logger),
loggingInterceptor,
validate.NewInterceptor(),
)

mux.Handle(dcimv1connect.NewSiteServiceHandler(s, interceptors))
mux.Handle(dcimv1connect.NewRoomServiceHandler(s, interceptors))
Expand Down
2 changes: 1 addition & 1 deletion api/pkg/proto/gen/v1/asset.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions api/pkg/proto/gen/v1/catalog.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading