Skip to content

Commit ea05506

Browse files
committed
update Makefile and run scripts to support the new feature
1 parent c41b4aa commit ea05506

File tree

5 files changed

+313
-178
lines changed

5 files changed

+313
-178
lines changed

Makefile

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,26 @@ git_commit=$(shell git describe --tags --always --dirty)
88
build_date=$(shell date -u '+%Y%m%d')
99
version=v${build_date}-${git_commit}
1010

11+
# Default build flags (can be overridden via BUILD_FLAGS env var)
12+
BUILD_FLAGS ?=
13+
1114
SOURCE_GIT_TAG=v1.0.0+$(shell git rev-parse --short=7 HEAD)
1215

1316
GO_LD_EXTRAFLAGS=-X github.com/openshift/ci-chat-bot/vendor/k8s.io/client-go/pkg/version.gitCommit=$(shell git rev-parse HEAD) -X github.com/openshift/ci-chat-bot/vendor/k8s.io/client-go/pkg/version.gitVersion=${SOURCE_GIT_TAG} -X sigs.k8s.io/prow/version.Name=ci-chat-bot -X sigs.k8s.io/prow/version.Version=${version}
1417
GOLINT=golangci-lint run
1518

19+
# Support for build flags (e.g., -tags gcs)
20+
GO_BUILD_FLAGS=$(BUILD_FLAGS)
21+
1622
debug:
17-
go build -gcflags="all=-N -l" ${GO_LD_FLAGS} -mod vendor -o ci-chat-bot ./cmd/...
23+
go build ${GO_BUILD_FLAGS} -gcflags="all=-N -l" ${GO_LD_FLAGS} -mod vendor -o ci-chat-bot ./cmd/...
1824
.PHONY: debug
1925

26+
# Override build target to support BUILD_FLAGS
27+
build:
28+
go build ${GO_BUILD_FLAGS} ${GO_LD_FLAGS} -mod vendor -o ci-chat-bot ./cmd/...
29+
.PHONY: build
30+
2031
vendor:
2132
go mod tidy
2233
go mod vendor
@@ -31,6 +42,38 @@ run:
3142
./hack/run.sh
3243
.PHONY: run
3344

45+
run-gcs:
46+
./hack/run-with-gcs.sh
47+
.PHONY: run-gcs
48+
49+
run-local:
50+
USE_GCS_ORGDATA=false ./hack/run.sh
51+
.PHONY: run-local
52+
53+
help-ci-chat-bot:
54+
@echo "CI Chat Bot specific targets:"
55+
@echo " build - Build ci-chat-bot binary"
56+
@echo " debug - Build with debug symbols"
57+
@echo " run - Run ci-chat-bot with hack/run.sh (auto-detects GCS vs local)"
58+
@echo " run-gcs - Run with GCS backend explicitly"
59+
@echo " run-local - Run with local file backend explicitly"
60+
@echo ""
61+
@echo "Build flags:"
62+
@echo " BUILD_FLAGS - Pass build flags (e.g., BUILD_FLAGS='-tags gcs' make build)"
63+
@echo ""
64+
@echo "Environment variables for hack scripts:"
65+
@echo " USE_GCS_ORGDATA - Set to 'true' to use GCS backend"
66+
@echo " GCS_BUCKET - GCS bucket name (default: resolved-org)"
67+
@echo " GCS_PROJECT_ID - GCS project ID (default: openshift-crt-mce)"
68+
@echo " ORGDATA_PATHS - Local orgdata file path"
69+
@echo " AUTH_CONFIG - Authorization config file path"
70+
@echo ""
71+
@echo "Examples:"
72+
@echo " make BUILD_FLAGS='-tags gcs' build # Build with GCS support"
73+
@echo " make run-gcs # Run with GCS backend"
74+
@echo " ORGDATA_PATHS=/my/file.json make run # Run with custom local file"
75+
.PHONY: help-ci-chat-bot
76+
3477
lint: verify-golint
3578

3679
sonar-reports:

hack/DEVELOPMENT.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Development Scripts Configuration
2+
3+
## Environment Variables
4+
5+
### Required Variables
6+
These must be set before running any hack scripts:
7+
8+
```bash
9+
export BOT_TOKEN="your-slack-bot-token"
10+
export BOT_SIGNING_SECRET="your-slack-signing-secret"
11+
```
12+
13+
### Optional Configuration
14+
15+
#### Organizational Data Backend
16+
17+
**Option 1: Use GCS Backend (Production)**
18+
```bash
19+
export USE_GCS_ORGDATA=true
20+
export GCS_BUCKET="resolved-org" # Default: resolved-org
21+
export GCS_OBJECT_PATH="orgdata/comprehensive_index_dump.json" # Default path
22+
export GCS_PROJECT_ID="openshift-crt-mce" # Default project
23+
export GCS_CHECK_INTERVAL="5m" # Default: 5 minutes
24+
export GCS_CREDENTIALS_JSON='{"type":"service_account",...}' # Optional: explicit creds
25+
```
26+
27+
**Option 2: Use Local Files (Development)**
28+
```bash
29+
export ORGDATA_PATHS="/path/to/your/comprehensive_index_dump.json"
30+
# Default: ../cyborg/org_tools/comprehensive_index_dump.json (relative to ci-chat-bot)
31+
```
32+
33+
#### Authorization Configuration
34+
```bash
35+
export AUTH_CONFIG="/path/to/your/authorization.yaml"
36+
# Default: ./test-authorization.yaml (relative to ci-chat-bot root)
37+
```
38+
39+
## GCS Authentication Setup
40+
41+
### Using Application Default Credentials (Recommended)
42+
```bash
43+
# Authenticate with gcloud
44+
gcloud auth login
45+
gcloud config set project openshift-crt-mce
46+
```
47+
48+
### Using Service Account (Production)
49+
```bash
50+
# Set credentials via environment variable
51+
export GCS_CREDENTIALS_JSON='{"type":"service_account",...}'
52+
53+
# OR via file
54+
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
55+
```
56+
57+
### GCS Bucket Security
58+
The GCS bucket should be configured with:
59+
-**Public access prevention**: Enforced
60+
-**Uniform bucket-level access**: Enabled
61+
-**IAM-based access control**: Project members only
62+
-**Bucket-level encryption**: Enabled
63+
64+
## Directory Structure Assumptions
65+
66+
The scripts assume this directory layout (relative to ci-chat-bot):
67+
```
68+
workspace/
69+
├── ci-chat-bot/ # This repository
70+
│ ├── hack/
71+
│ │ ├── run.sh # Main development script
72+
│ │ └── run-with-gcs.sh # GCS convenience script
73+
│ └── test-authorization.yaml # Default auth config
74+
├── cyborg/ # Optional: orgdata repository
75+
│ └── org_tools/
76+
│ └── comprehensive_index_dump.json
77+
└── release/ # OpenShift release repository (required)
78+
├── ci-operator/
79+
└── core-services/
80+
```
81+
82+
## Usage Examples
83+
84+
### Quick Start with GCS
85+
```bash
86+
# Set required tokens
87+
export BOT_TOKEN="xoxb-your-token"
88+
export BOT_SIGNING_SECRET="your-secret"
89+
90+
# Use GCS backend
91+
./hack/run-with-gcs.sh
92+
```
93+
94+
### Development with Local Files
95+
```bash
96+
# Set required tokens
97+
export BOT_TOKEN="xoxb-your-token"
98+
export BOT_SIGNING_SECRET="your-secret"
99+
100+
# Point to your local orgdata file
101+
export ORGDATA_PATHS="/your/path/to/comprehensive_index_dump.json"
102+
103+
# Run with local file backend
104+
./hack/run.sh
105+
```
106+
107+
### Custom Configuration
108+
```bash
109+
# Required tokens
110+
export BOT_TOKEN="xoxb-your-token"
111+
export BOT_SIGNING_SECRET="your-secret"
112+
113+
# Custom GCS configuration
114+
export USE_GCS_ORGDATA=true
115+
export GCS_BUCKET="my-org-bucket"
116+
export GCS_PROJECT_ID="my-project"
117+
export GCS_CREDENTIALS_JSON="$(cat /path/to/service-account.json)"
118+
119+
# Custom auth config
120+
export AUTH_CONFIG="/path/to/my-auth-config.yaml"
121+
122+
./hack/run.sh
123+
```
124+
125+
## Script Behavior
126+
127+
1. **`hack/run.sh`** - Main development script
128+
- Detects GCS vs local file mode via `USE_GCS_ORGDATA`
129+
- Uses sensible defaults for file paths relative to project
130+
- Extracts secrets from OpenShift CI clusters
131+
- Builds and runs ci-chat-bot with appropriate flags
132+
133+
2. **`hack/run-with-gcs.sh`** - Convenience wrapper
134+
- Sets `USE_GCS_ORGDATA=true`
135+
- Uses production GCS defaults
136+
- Calls `hack/run.sh`
137+
138+
## Troubleshooting
139+
140+
### File Not Found Errors
141+
If you see errors about missing files:
142+
1. Check that `ORGDATA_PATHS` points to a valid file
143+
2. Ensure the `../cyborg` directory exists if using defaults
144+
3. Verify the `../release` directory exists (OpenShift release repo)
145+
146+
### GCS Authentication Errors
147+
If GCS fails to authenticate:
148+
1. **Check authentication**: `gcloud auth list`
149+
2. **Test access**: `gcloud storage ls gs://resolved-org/orgdata/`
150+
3. **Verify permissions**: Check bucket IAM settings
151+
4. **Try service account**: Set `GCS_CREDENTIALS_JSON` if ADC fails
152+
153+
Common GCS errors:
154+
- **"Authentication failed"**: Run `gcloud auth login`
155+
- **"Access denied"**: Check bucket IAM permissions
156+
- **"Object not found"**: Verify `GCS_BUCKET` and `GCS_OBJECT_PATH`
157+
158+
### Authorization Issues
159+
If authorization is too restrictive:
160+
1. Check `AUTH_CONFIG` points to a valid YAML file
161+
2. Review the authorization rules in that file
162+
3. Set `AUTH_CONFIG=""` to disable authorization for testing
163+
164+
### Migration from File-based to GCS
165+
1. **Upload your existing data**:
166+
```bash
167+
gcloud storage cp comprehensive_index_dump.json gs://resolved-org/orgdata/
168+
```
169+
2. **Test GCS access**: `./hack/run-with-gcs.sh`
170+
3. **Update your workflow**: Set `USE_GCS_ORGDATA=true` in your environment

0 commit comments

Comments
 (0)