diff --git a/Dockerfile.ocp b/Dockerfile.ocp new file mode 100644 index 0000000..e5a54c6 --- /dev/null +++ b/Dockerfile.ocp @@ -0,0 +1,18 @@ +# ---- build stage ---- +FROM node:18-alpine AS build +WORKDIR /app + +# (optional) allow overriding paddles URL at build time +ARG REACT_APP_PADDLES_SERVER +ENV REACT_APP_PADDLES_SERVER=$REACT_APP_PADDLES_SERVER + +COPY package*.json ./ +RUN npm install + +COPY . . +RUN npm run build + +# ---- runtime stage ---- +FROM nginxinc/nginx-unprivileged:stable-alpine +COPY --from=build /app/build /usr/share/nginx/html +COPY openshift/nginx/default.conf /etc/nginx/conf.d/default.conf diff --git a/README.md b/README.md index 02342ab..ab4550d 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ In [teuthology's docker-compose](https://github.com/ceph/teuthology/blob/main/do ports: - 8081:8081 ``` -[recommended] For developement purposes: +[recommended] For development purposes: Add the following to `pulpito-ng` container: ``` @@ -51,4 +51,68 @@ pulpito-ng: volumes: - ../../../pulpito-ng:/app/:rw - /app/node_modules -``` \ No newline at end of file +``` + +## Deploying in OpenShift + +``Dockerfile.ocp`` and the files under ``openshift/`` are files used to deploy pulpito-ng in OpenShift. + +You may wish to change the number of replicas in ``openshift/pulpito-ng-deploy.yaml`` depending on how many worker nodes you have. + +To deploy: + +Create a new project (if necessary) +``` +oc new-project pulpito +``` + +Create the Image Stream +``` +oc -n pulpito apply -f openshift/pulpito-ng-imagestream.yaml +``` + +Modify the Build Config if necessary and start the build +``` +oc -n pulpito apply -f openshift/pulpito-ng-build.yaml +``` + +Define the paddles URL +``` +oc -n pulpito set env bc/pulpito-ng \ + REACT_APP_PADDLES_SERVER=http://paddles.example.com +``` + +Start the build +``` +oc -n pulpito start-build pulpito-ng --follow +``` + +Deploy! +``` +oc -n pulpito apply -f openshift/pulpito-ng-deploy.yaml + +oc -n pulpito get route pulpito-ng +``` + +### Deploying code changes in OpenShift + +If you just want to deploy the latest code in ``main`` (and your Build Config in ``openshift/pulpito-ng-build.yaml`` doesn't have a different branch defined), + +(Note, the ``--follow`` will likely timout if you do not wait for the first build from above to finish) +``` +oc -n pulpito start-build pulpito-ng --follow +``` + +If you wish to deploy code from a different pulpito-ng.git branch, + +Start a one-off build of the branch. The deployment will automatically roll this out. +``` +oc -n pulpito start-build pulpito-ng --follow --commit= +``` + +To make the deployment use this branch permanently, modify ``spec.source.git.ref:`` in ``openshift/pulpito-ng-build.yaml``, and build it: +``` +oc -n pulpito apply -f openshift/pulpito-ng-build.yaml + +oc -n pulpito start-build pulpito-ng --follow +``` diff --git a/openshift/nginx/default.conf b/openshift/nginx/default.conf new file mode 100644 index 0000000..84a44a2 --- /dev/null +++ b/openshift/nginx/default.conf @@ -0,0 +1,13 @@ +# Note: This file is intended for OCP-based deployments +server { + listen 8080; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # SPA routes: anything that isn't a real file falls back to index.html + location / { + try_files $uri $uri/ /index.html; + } +} diff --git a/openshift/pulpito-ng-build.yaml b/openshift/pulpito-ng-build.yaml new file mode 100644 index 0000000..d42e491 --- /dev/null +++ b/openshift/pulpito-ng-build.yaml @@ -0,0 +1,21 @@ +apiVersion: build.openshift.io/v1 +kind: BuildConfig +metadata: + name: pulpito-ng +spec: + runPolicy: Serial + source: + type: Git + git: + uri: https://github.com/ceph/pulpito-ng + ref: main + strategy: + type: Docker + dockerStrategy: + dockerfilePath: Dockerfile.ocp + output: + to: + kind: ImageStreamTag + name: pulpito-ng:latest + triggers: + - type: ConfigChange diff --git a/openshift/pulpito-ng-deploy.yaml b/openshift/pulpito-ng-deploy.yaml new file mode 100644 index 0000000..2218069 --- /dev/null +++ b/openshift/pulpito-ng-deploy.yaml @@ -0,0 +1,78 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: pulpito-ng + labels: + app: pulpito-ng + annotations: + # When the BuildConfig updates the ImageStreamTag pulpito-ng:latest, + # automatically roll out the Deployment to the new image. + image.openshift.io/triggers: >- + [{"from":{"kind":"ImageStreamTag","name":"pulpito-ng:latest"}, + "fieldPath":"spec.template.spec.containers[?(@.name==\"pulpito-ng\")].image"}] +spec: + replicas: 2 + revisionHistoryLimit: 10 + progressDeadlineSeconds: 300 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + selector: + matchLabels: + app: pulpito-ng + template: + metadata: + labels: + app: pulpito-ng + spec: + containers: + - name: pulpito-ng + # This gets rewritten by the ImageStream trigger above. + image: pulpito-ng:latest + imagePullPolicy: Always + ports: + - name: http + containerPort: 8080 + readinessProbe: + httpGet: + path: / + port: http + initialDelaySeconds: 3 + timeoutSeconds: 2 + periodSeconds: 5 + failureThreshold: 6 + livenessProbe: + httpGet: + path: / + port: http + initialDelaySeconds: 10 + timeoutSeconds: 2 + periodSeconds: 10 + failureThreshold: 3 +--- +apiVersion: v1 +kind: Service +metadata: + name: pulpito-ng + labels: + app: pulpito-ng +spec: + selector: + app: pulpito-ng + ports: + - name: http + port: 8080 + targetPort: http +--- +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + name: pulpito-ng +spec: + to: + kind: Service + name: pulpito-ng + port: + targetPort: http diff --git a/openshift/pulpito-ng-imagestream.yaml b/openshift/pulpito-ng-imagestream.yaml new file mode 100644 index 0000000..3d70a4f --- /dev/null +++ b/openshift/pulpito-ng-imagestream.yaml @@ -0,0 +1,4 @@ +apiVersion: image.openshift.io/v1 +kind: ImageStream +metadata: + name: pulpito-ng