Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update index server build scripts and deployment #147

Merged
merged 23 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e6e2df9
registry-viewer repo cloning replaced with devfile-web repo cloning, …
michael-valdron Oct 7, 2022
db52dd6
index server image build updated to remove old registry-viewer resour…
michael-valdron Oct 7, 2022
21d6e7f
entrypoint script for index server no longer starts separate registry…
michael-valdron Oct 7, 2022
ed06e0c
removed old registry viewer helm chart configs.
michael-valdron Oct 17, 2022
a057944
Registry Viewer build & export removed from devfile-index-base image …
michael-valdron Oct 14, 2022
a9aafdc
removed unneeded registry viewer steps to create environment variable…
michael-valdron Oct 18, 2022
f5cebc2
headless env var added to index server build scripts.
michael-valdron Oct 21, 2022
05c4c21
index server captures headless env var
michael-valdron Oct 21, 2022
86ab0c0
headless mode added to index server, error handling for registry view…
michael-valdron Oct 21, 2022
2b717bb
headless index server helm chart created.
michael-valdron Oct 21, 2022
0c39557
registry viewer container and values added to devfile-registry helm c…
michael-valdron Oct 21, 2022
73c2fb0
index server deploy guide in README updated to include headless deplo…
michael-valdron Oct 21, 2022
431a44e
Test for registry viewer headless handler added.
michael-valdron Nov 1, 2022
044a5c3
write err handling added for response writing under registry viewer e…
michael-valdron Nov 1, 2022
ad40d16
Builder for proxy server error responses added with test cases.
michael-valdron Nov 1, 2022
39a109f
registry viewer resource attributes added to devfile-registry chart.
michael-valdron Nov 7, 2022
3542690
fixed headless to be deployed with the same helm chart.
michael-valdron Nov 8, 2022
2aa95c8
helm chart docs updated.
michael-valdron Nov 10, 2022
1b96189
headless mode env var is now set on deployment.
michael-valdron Nov 15, 2022
016e487
revisions to README applied.
michael-valdron Nov 15, 2022
116b195
set registry viewer env vars for deployment
michael-valdron Nov 15, 2022
e41c199
registry hosts value added for env var in helm chart deployment templ…
michael-valdron Nov 18, 2022
07c5525
review revisions applied.
michael-valdron Nov 21, 2022
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
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ $ helm install devfile-registry ./deploy/chart/devfile-registry \
--set devfileIndex.tag=latest
```

You can deploy a devfile registry with a custom registry viewer image (uses `quay.io/devfile/registry-viewer:next` by default) by running the following:
michael-valdron marked this conversation as resolved.
Show resolved Hide resolved

```bash
$ helm install devfile-registry ./deploy/chart/devfile-registry \
--set global.ingress.domain="$(minikube ip).nip.io" \
--set devfileIndex.image=quay.io/someuser/devfile-index \
--set devfileIndex.tag=latest \
--set registryViewer.image=quay.io/someuser/registry-viewer \
--set registryViewer.tag=latest
```

You can deploy a *headless* devfile registry (i.e. without the registry viewer) by specifying `--set global.headless=true` which will look like:

```bash
$ helm install devfile-registry ./deploy/chart/devfile-registry \
--set global.ingress.domain="$(minikube ip).nip.io" \
--set global.headless=true \
--set devfileIndex.image=quay.io/someuser/devfile-index \
--set devfileIndex.tag=latest
```

For more information on the Helm chart, consult [its readme](deploy/chart/devfile-registry/README.md).

## Contributing
Expand Down
38 changes: 22 additions & 16 deletions deploy/chart/devfile-registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,25 @@ The following fields can be configured in the Helm chart, either via the `values

| Parameter | Description | Default |
| ----------------------- | --------------------------------------------- | ---------------------------------------------------------- |
| `global.ingress.domain` | Ingress domain for the devfile registry | **MUST BE SET BY USER** |
| `global.ingress.class` | Ingress class for the devfile registry | `nginx` |
| `global.ingress.secretName` | Name of an existing tls secret if using TLS | ` '' ` |
| `global.isOpenShift ` | Set to true to use OpenShift routes instead of ingress | `false` |
| `global.tlsEnabled` | Set to true to use the devfile registry with TLS | `false` |
| `devfileIndex.image` | Image used for the devfile index image | `quay.io/devfile/devfile-index` |
| `devfileIndex.tag` | Tag for devfile index image | `next` |
| `devfileIndex.imagePullpolicy` | Image pull policy for devfile index image | `Always` |
| `devfileIndex.memoryLimit` | Memory for devfile index container | `256Mi` |
| `ociRegistry.image` | Image used for the oci registry image | `quay.io/devfile/oci-registry` |
| `ociRegistry.tag` | Tag for oci registry image | `next` |
| `ociRegistry.imagePullpolicy` | Image pull policy for oci registry image | `Always` |
| `ociRegistry.memoryLimit` | Memory for oci registry container | `256Mi` |
| `persistence.enabled` | Enable persistent storage for the registry | `true` |
| `persistence.size` | The size of the persistent volume (if-enabled) | `1Gi` |
| `telemetry.key` | The write key for the Segment instance | **MUST BE SET BY USER** |
| `global.ingress.domain` | Ingress domain for the devfile registry | **MUST BE SET BY USER** |
| `global.ingress.class` | Ingress class for the devfile registry | `nginx` |
| `global.ingress.secretName` | Name of an existing tls secret if using TLS | ` '' ` |
| `global.isOpenShift ` | Set to true to use OpenShift routes instead of ingress | `false` |
| `global.tlsEnabled` | Set to true to use the devfile registry with TLS | `false` |
| `global.headless` | Set to true to run in headless mode (does not expect attached registry viewer) | `false` |
| `devfileIndex.image` | Image used for the devfile index image | `quay.io/devfile/devfile-index` |
| `devfileIndex.tag` | Tag for devfile index image | `next` |
| `devfileIndex.imagePullpolicy` | Image pull policy for devfile index image | `Always` |
| `devfileIndex.memoryLimit` | Memory for devfile index container | `256Mi` |
| `registryViewer.image` | Image used for the registry viewer image | `quay.io/devfile/registry-viewer` |
| `registryViewer.tag` | Tag for registry viewer image | `next` |
| `registryViewer.imagePullpolicy` | Image pull policy for registry viewer image | `Always` |
| `registryViewer.memoryLimit` | Memory for registry viewer container | `256Mi` |
| `ociRegistry.image` | Image used for the oci registry image | `quay.io/devfile/oci-registry` |
| `ociRegistry.tag` | Tag for oci registry image | `next` |
| `ociRegistry.imagePullpolicy` | Image pull policy for oci registry image | `Always` |
| `ociRegistry.memoryLimit` | Memory for oci registry container | `256Mi` |
| `persistence.enabled` | Enable persistent storage for the registry | `true` |
| `persistence.size` | The size of the persistent volume (if-enabled) | `1Gi` |
| `telemetry.key` | The write key for the Segment instance | **MUST BE SET BY USER** |
| `telemetry.registryViewerWriteKey` | The write key for the registry viewer | **MUST BE SET BY USER** |
10 changes: 5 additions & 5 deletions deploy/chart/devfile-registry/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ data:
prometheus:
enabled: true
path: /metrics

devfile-registry-hosts.json: |
michael-valdron marked this conversation as resolved.
Show resolved Hide resolved
{
"Community": {
"url": "http://localhost:8080"
[
{
"name": "Community",
"link": "http://localhost:8080"
}
}
]
66 changes: 46 additions & 20 deletions deploy/chart/devfile-registry/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ spec:
items:
- key: registry-config.yml
path: config.yml
- name: viewer-config
configMap:
name: {{ template "devfileregistry.fullname" . }}
items:
- key: devfile-registry-hosts.json
path: devfile-registry-hosts.json

containers:
- image: "{{ .Values.devfileIndex.image }}:{{ .Values.devfileIndex.tag }}"
Expand All @@ -80,32 +74,64 @@ spec:
scheme: HTTP
initialDelaySeconds: 15
periodSeconds: 10
timeoutSeconds: 3
resources:
limits:
memory: {{ .Values.devfileIndex.memoryLimit }}
requests:
memory: 64Mi
env:
- name: REGISTRY_NAME
value: {{ .Values.telemetry.registryName }}
- name: TELEMETRY_KEY
value: {{ .Values.telemetry.key }}
- name: REGISTRY_HEADLESS
value: "{{ .Values.global.headless }}"
{{- if not .Values.global.headless }}
- image: "{{ .Values.registryViewer.image }}:{{ .Values.registryViewer.tag }}"
imagePullPolicy: {{ .Values.registryViewer.imagePullPolicy }}
name: registry-viewer
ports:
livenessProbe:
httpGet:
path: /viewer
port: 3000
scheme: HTTP
initialDelaySeconds: 15
periodSeconds: 10
timeoutSeconds: 3
readinessProbe:
michael-valdron marked this conversation as resolved.
Show resolved Hide resolved
httpGet:
path: /viewer
port: 3000
scheme: HTTP
initialDelaySeconds: 15
periodSeconds: 10
timeoutSeconds: 3
startupProbe:
httpGet:
path: /viewer
port: 8080
port: 3000
scheme: HTTP
initialDelaySeconds: 30
periodSeconds: 1
timeoutSeconds: 10
timeoutSeconds: 10
resources:
limits:
memory: {{ .Values.devfileIndex.memoryLimit }}
memory: {{ .Values.registryViewer.memoryLimit }}
requests:
memory: 64Mi
env:
- name: DEVFILE_VIEWER_ROOT
michael-valdron marked this conversation as resolved.
Show resolved Hide resolved
value: "/viewer"
- name: REGISTRY_NAME
value: {{ .Values.telemetry.registryName }}
- name: TELEMETRY_KEY
value: {{ .Values.telemetry.key }}
volumeMounts:
- name: viewer-config
mountPath: "/app/config"
readOnly: false

- name: NEXT_PUBLIC_BASE_PATH
value: /viewer
- name: NEXT_PUBLIC_DEVFILE_REGISTRIES
valueFrom:
configMapKeyRef:
name: {{ template "devfileregistry.fullname" . }}
key: devfile-registry-hosts.json
- name: NEXT_PUBLIC_ANALYTICS_WRITE_KEY
value: {{ .Values.telemetry.registryViewerWriteKey }}
{{- end }}
- image: "{{ .Values.ociRegistry.image }}:{{ .Values.ociRegistry.tag }}"
imagePullPolicy: {{ .Values.ociRegistry.imagePullPolicy }}
name: oci-registry
Expand Down
7 changes: 7 additions & 0 deletions deploy/chart/devfile-registry/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@ global:
secretName: ''
isOpenShift: false
tlsEnabled: false
headless: false

devfileIndex:
image: quay.io/devfile/devfile-index
tag: next
imagePullPolicy: Always
memoryLimit: 256Mi

registryViewer:
image: quay.io/devfile/registry-viewer
tag: next
imagePullPolicy: Always
memoryLimit: 256Mi

ociRegistry:
image: quay.io/devfile/oci-registry
tag: next
Expand Down
21 changes: 1 addition & 20 deletions index/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ COPY . .
RUN CGO_ENABLED=0 go build -mod=vendor -o index-server main.go

# Application image
FROM registry.access.redhat.com/ubi8/nodejs-14-minimal AS runner
FROM registry.access.redhat.com/ubi8/ubi-minimal AS runner
USER root

# Install and configure dependencies
Expand All @@ -24,25 +24,6 @@ RUN set -x ; \
# Modify the permissions on the necessary files to allow the container to properly run as a non-root UID
RUN mkdir -p /www/data && chmod -R g+rwx /www/data

WORKDIR /app

# Copy over the registry viewer's resources
COPY --from=registry-viewer --chown=www-data:root /app/next.config.js ./
COPY --from=registry-viewer --chown=www-data:root /app/public ./public
COPY --from=registry-viewer --chown=www-data:root /app/.next ./.next
COPY --from=registry-viewer /app/node_modules ./node_modules
COPY --from=registry-viewer /app/package.json ./package.json
COPY --from=registry-viewer --chown=www-data:root /app/config ./config

# Make sure .next is writable
RUN chmod -R g+rwx /app/.next

# Run the registry viewer in production
ENV NODE_ENV production

ENV DEVFILE_VIEWER_ROOT /viewer
ENV DEVFILE_COMMUNITY_HOST false

# Set env vars for the locations of the devfile stacks and index.json
ENV DEVFILE_STACKS /registry/stacks
ENV DEVFILE_SAMPLES /registry/samples
Expand Down
9 changes: 0 additions & 9 deletions index/server/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,5 @@
# Build the index container for the registry
buildfolder="$(realpath $(dirname ${BASH_SOURCE[0]}))"

# Clone the registry-support repo
if [ -d $buildfolder/registry-viewer ]; then
rm -rf $buildfolder/registry-viewer
fi
git clone https://github.com/devfile/registry-viewer.git $buildfolder/registry-viewer

# Build the registry viewer
docker build -t registry-viewer --target builder --build-arg DEVFILE_VIEWER_ROOT=/viewer --build-arg DEVFILE_COMMUNITY_HOST=false $buildfolder/registry-viewer

# Build the index server
docker build -t devfile-index-base:latest $buildfolder
9 changes: 0 additions & 9 deletions index/server/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,5 @@ if [ ! -e "$DEVFILE_INDEX" ]; then
exit 1
fi

# Start the registry viewer
npm start &

# Wait for server to start
until $(curl --output /dev/null --silent --head --fail http://localhost:3000/viewer); do
printf '.'
sleep 1
done

# Start the index server
/registry/index-server
1 change: 1 addition & 0 deletions index/server/pkg/server/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var (
sampleBase64IndexPath = os.Getenv("DEVFILE_SAMPLE_BASE64_INDEX")
stackIndexPath = os.Getenv("DEVFILE_STACK_INDEX")
stackBase64IndexPath = os.Getenv("DEVFILE_STACK_BASE64_INDEX")
headless = util.IsEnabled("REGISTRY_HEADLESS", false)
enableTelemetry = util.IsTelemetryEnabled()
registry = util.GetOptionalEnv("REGISTRY_NAME", "devfile-registry")
)
32 changes: 32 additions & 0 deletions index/server/pkg/server/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"path"
"path/filepath"
"regexp"
"strings"

"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/parser"
Expand Down Expand Up @@ -309,6 +310,12 @@ func serveDevfileStarterProjectWithVersion(c *gin.Context) {
}
}

// serveHeadlessUI handles registry viewer proxy requests in headless mode
func serveHeadlessUI(c *gin.Context) {
c.String(http.StatusBadRequest, "registry viewer is not available in headless mode")
}

// serveUI handles registry viewer proxy requests in headed mode
func serveUI(c *gin.Context) {
remote, err := url.Parse(scheme + "://" + viewerService + "/viewer/")
if err != nil {
Expand All @@ -327,6 +334,11 @@ func serveUI(c *gin.Context) {
req.URL.Host = remote.Host
}

// Setup registry viewer proxy error response
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
buildProxyErrorResponse(w, r, err, "registry viewer")
}

proxy.ServeHTTP(c.Writer, c.Request)
}

Expand Down Expand Up @@ -457,6 +469,26 @@ func buildIndexAPIResponse(c *gin.Context, wantV1Index bool) {
}
}

// buildProxyErrorResponse builds an error response for proxy routes
func buildProxyErrorResponse(w http.ResponseWriter, r *http.Request, err error, name string) {
var writeErr error

log.Print(err.Error())

if strings.Contains(err.Error(), "connection refused") {
w.WriteHeader(http.StatusBadGateway)
_, writeErr = w.Write([]byte(fmt.Sprintf("%s is not accessible", name)))

} else {
w.WriteHeader(http.StatusInternalServerError)
_, writeErr = w.Write([]byte("internal server error"))
}

if writeErr != nil {
log.Print(writeErr.Error())
}
}

// fetchDevfile retrieves a specified devfile by fetching stacks from the OCI
// registry and samples from the `samplesPath` given by server. Also retrieves index
// schema from `indexPath` given by server.
Expand Down
Loading