From 24182e2dbd6bd7669941a3cfaf22bfaea57b3020 Mon Sep 17 00:00:00 2001 From: Jeremy Ho Date: Fri, 20 Dec 2019 12:04:03 -0800 Subject: [PATCH] Update build config to custom docker strategy Collapse Dockerfile into app.bc.yaml Update openshift template indentations Signed-off-by: Jeremy Ho --- app/.dockerignore | 4 - app/Dockerfile | 24 ---- openshift/app.bc.yaml | 195 +++++++++++++++++-------------- openshift/app.dc.yaml | 264 +++++++++++++++++++++--------------------- 4 files changed, 241 insertions(+), 246 deletions(-) delete mode 100644 app/.dockerignore delete mode 100644 app/Dockerfile diff --git a/app/.dockerignore b/app/.dockerignore deleted file mode 100644 index 5547bd4..0000000 --- a/app/.dockerignore +++ /dev/null @@ -1,4 +0,0 @@ -coverage -dist -node_modules -Dockerfile diff --git a/app/Dockerfile b/app/Dockerfile deleted file mode 100644 index 5f12c43..0000000 --- a/app/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -FROM mhart/alpine-node:12 - -ARG APP_ROOT=/opt/app-root/src - -ENV PATH="/usr/lib/libreoffice/program:${PATH}" \ - PYTHONUNBUFFERED=1 - -WORKDIR ${APP_ROOT} - -# Install LibreOffice & Common Fonts -RUN apk --no-cache add bash libreoffice util-linux \ - ttf-droid-nonlatin ttf-droid ttf-dejavu ttf-freefont ttf-liberation \ - && rm -rf /var/cache/apk/* - -# Fix Python/LibreOffice Integration -COPY docker ${APP_ROOT}/docker -RUN ${APP_ROOT}/docker/bindPython.sh - -# Install CDOGS -COPY . . -RUN npm ci - -EXPOSE 3000 -CMD ["npm", "run", "start"] diff --git a/openshift/app.bc.yaml b/openshift/app.bc.yaml index 480249d..fdb1857 100644 --- a/openshift/app.bc.yaml +++ b/openshift/app.bc.yaml @@ -7,91 +7,114 @@ labels: metadata: name: "${REPO_NAME}-app-bc" objects: -- apiVersion: v1 - kind: ImageStream - metadata: - annotations: - openshift.io/generated-by: OpenShiftNewBuild - name: nodejs-10 - spec: - lookupPolicy: - local: false - tags: - - annotations: - openshift.io/imported-from: registry.access.redhat.com/rhoar-nodejs/nodejs-10:latest - from: - kind: DockerImage - name: registry.access.redhat.com/rhoar-nodejs/nodejs-10:latest - generation: - importPolicy: - scheduled: true - name: latest - referencePolicy: - type: Local -- apiVersion: v1 - kind: ImageStream - metadata: - annotations: - openshift.io/generated-by: OpenShiftNewBuild - name: "${REPO_NAME}-app" - spec: - lookupPolicy: - local: false -- apiVersion: v1 - kind: BuildConfig - metadata: - annotations: - openshift.io/generated-by: OpenShiftNewBuild - name: "${REPO_NAME}-app-${JOB_NAME}" - spec: - completionDeadlineSeconds: 600 - successfulBuildsHistoryLimit: 3 - failedBuildsHistoryLimit: 3 - nodeSelector: - output: - to: - kind: ImageStreamTag - name: "${REPO_NAME}-app:latest" - postCommit: {} - resources: - requests: - cpu: 1000m - memory: 1Gi - limits: - cpu: 2000m - memory: 2Gi - runPolicy: SerialLatestOnly - source: - contextDir: app - git: - ref: "${SOURCE_REPO_REF}" - uri: "${SOURCE_REPO_URL}" - type: Git - strategy: - sourceStrategy: - env: - - name: BUILD_LOGLEVEL - value: '2' - - name: NPM_CONFIG_LOGLEVEL - value: notice - from: + - apiVersion: v1 + kind: ImageStream + metadata: + annotations: + openshift.io/generated-by: OpenShiftNewBuild + name: nodejs-10 + spec: + lookupPolicy: + local: false + tags: + - annotations: + openshift.io/imported-from: registry.access.redhat.com/rhoar-nodejs/nodejs-10:latest + from: + kind: DockerImage + name: registry.access.redhat.com/rhoar-nodejs/nodejs-10:latest + generation: + importPolicy: + scheduled: true + name: latest + referencePolicy: + type: Local + - apiVersion: v1 + kind: ImageStream + metadata: + annotations: + openshift.io/generated-by: OpenShiftNewBuild + name: "${REPO_NAME}-app" + spec: + lookupPolicy: + local: false + - apiVersion: v1 + kind: BuildConfig + metadata: + annotations: + openshift.io/generated-by: OpenShiftNewBuild + name: "${REPO_NAME}-app-${JOB_NAME}" + spec: + completionDeadlineSeconds: 600 + failedBuildsHistoryLimit: 3 + nodeSelector: + output: + to: kind: ImageStreamTag - name: nodejs-10:latest - type: Source + name: "${REPO_NAME}-app:latest" + postCommit: {} + resources: + requests: + cpu: 1000m + memory: 1Gi + limits: + cpu: 2000m + memory: 2Gi + runPolicy: SerialLatestOnly + source: + contextDir: app + git: + ref: "${SOURCE_REPO_REF}" + uri: "${SOURCE_REPO_URL}" + type: Git + dockerfile: |- + FROM BuildConfig + ARG APP_ROOT=/opt/app-root/src + ENV PATH="/usr/lib/libreoffice/program:${PATH}" \ + PYTHONUNBUFFERED=1 + WORKDIR ${APP_ROOT} + + # Install LibreOffice & Common Fonts + RUN apk --no-cache add bash libreoffice util-linux \ + ttf-droid-nonlatin ttf-droid ttf-dejavu ttf-freefont ttf-liberation \ + && rm -rf /var/cache/apk/* + + # Fix Python/LibreOffice Integration + COPY docker ${APP_ROOT}/docker + RUN chmod a+rx ${APP_ROOT}/docker/bindPython.sh \ + && ${APP_ROOT}/docker/bindPython.sh + + # Install CDOGS + COPY . . + RUN npm ci + + EXPOSE 3000 + CMD ["npm", "run", "start"] + strategy: + dockerStrategy: + env: + - name: BUILD_LOGLEVEL + value: "2" + - name: NPM_CONFIG_LOGLEVEL + value: notice + from: + kind: DockerImage + name: "mhart/alpine-node:12" + type: Docker + successfulBuildsHistoryLimit: 3 parameters: -- name: REPO_NAME - description: Application repository name - displayName: Repository Name - required: true -- name: JOB_NAME - description: Job identifier (i.e. 'pr-5' OR 'master') - displayName: Job Branch Name - required: true -- name: SOURCE_REPO_REF - description: Git Pull Request Reference (i.e. 'pull/CHANGE_ID/head') - displayName: Source Repository Reference - required: true -- name: SOURCE_REPO_URL - description: Git Repository URL - displayName: Source Repository URL - required: true + - name: REPO_NAME + description: Application repository name + displayName: Repository Name + required: true + - name: JOB_NAME + description: Job identifier (i.e. 'pr-5' OR 'master') + displayName: Job Branch Name + required: true + - name: SOURCE_REPO_REF + description: Git Pull Request Reference (i.e. 'pull/CHANGE_ID/head') + displayName: Source Repository Reference + required: true + - name: SOURCE_REPO_URL + description: Git Repository URL + displayName: Source Repository URL + required: true diff --git a/openshift/app.dc.yaml b/openshift/app.dc.yaml index 0cac737..1eea41e 100644 --- a/openshift/app.dc.yaml +++ b/openshift/app.dc.yaml @@ -7,138 +7,138 @@ labels: metadata: name: "${REPO_NAME}-app-dc" objects: -- apiVersion: v1 - kind: DeploymentConfig - metadata: - annotations: - openshift.io/generated-by: OpenShiftNewApp - name: "${APP_NAME}-app-${JOB_NAME}" - spec: - replicas: 2 - selector: - app: "${APP_NAME}-${JOB_NAME}" - deploymentconfig: "${APP_NAME}-app-${JOB_NAME}" - strategy: - type: Rolling - rollingParams: - timeoutSeconds: 600 - resources: {} - template: - metadata: - annotations: - openshift.io/generated-by: OpenShiftNewApp - labels: - app: "${APP_NAME}-${JOB_NAME}" - deploymentconfig: "${APP_NAME}-app-${JOB_NAME}" - spec: - containers: - - image: docker-registry.default.svc:5000/${NAMESPACE}/${REPO_NAME}-app:${JOB_NAME} - imagePullPolicy: IfNotPresent - livenessProbe: - failureThreshold: 3 - httpGet: - path: / - port: 3000 - scheme: HTTP - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 1 - name: "${APP_NAME}-app-${JOB_NAME}" - ports: - - containerPort: 3000 - protocol: TCP - readinessProbe: - failureThreshold: 3 - httpGet: - path: / - port: 3000 - scheme: HTTP - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 1 + - apiVersion: v1 + kind: DeploymentConfig + metadata: + annotations: + openshift.io/generated-by: OpenShiftNewApp + name: "${APP_NAME}-app-${JOB_NAME}" + spec: + replicas: 2 + selector: + app: "${APP_NAME}-${JOB_NAME}" + deploymentconfig: "${APP_NAME}-app-${JOB_NAME}" + strategy: + type: Rolling + rollingParams: + timeoutSeconds: 600 resources: {} - env: - - name: NODE_ENV - value: production - - name: KC_CLIENTID - valueFrom: - secretKeyRef: - key: username - name: cdogs-keycloak-secret - - name: KC_CLIENTSECRET - valueFrom: - secretKeyRef: - key: password - name: cdogs-keycloak-secret - envFrom: - - configMapRef: - name: cdogs-keycloak-config - - configMapRef: - name: cdogs-server-config - test: false - triggers: - - type: ConfigChange - - imageChangeParams: - automatic: true - containerNames: - - "${APP_NAME}-app-${JOB_NAME}" - from: - kind: ImageStreamTag - name: "${REPO_NAME}-app:${JOB_NAME}" - namespace: "${NAMESPACE}" - type: ImageChange -- apiVersion: v1 - kind: Service - metadata: - annotations: - openshift.io/generated-by: OpenShiftNewApp - name: "${APP_NAME}-app-${JOB_NAME}" - spec: - ports: - - name: 3000-tcp - port: 3000 - protocol: TCP - targetPort: 3000 - selector: - app: "${APP_NAME}-${JOB_NAME}" - deploymentconfig: "${APP_NAME}-app-${JOB_NAME}" -- apiVersion: v1 - kind: Route - metadata: - annotations: - openshift.io/host.generated: 'true' - name: "${APP_NAME}-app-${JOB_NAME}" - spec: - host: "${HOST_ROUTE}" - path: / - port: - targetPort: 3000-tcp - tls: - insecureEdgeTerminationPolicy: Redirect - termination: edge - to: - kind: Service + template: + metadata: + annotations: + openshift.io/generated-by: OpenShiftNewApp + labels: + app: "${APP_NAME}-${JOB_NAME}" + deploymentconfig: "${APP_NAME}-app-${JOB_NAME}" + spec: + containers: + - image: docker-registry.default.svc:5000/${NAMESPACE}/${REPO_NAME}-app:${JOB_NAME} + imagePullPolicy: IfNotPresent + livenessProbe: + failureThreshold: 3 + httpGet: + path: / + port: 3000 + scheme: HTTP + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + name: "${APP_NAME}-app-${JOB_NAME}" + ports: + - containerPort: 3000 + protocol: TCP + readinessProbe: + failureThreshold: 3 + httpGet: + path: / + port: 3000 + scheme: HTTP + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + resources: {} + env: + - name: NODE_ENV + value: production + - name: KC_CLIENTID + valueFrom: + secretKeyRef: + key: username + name: cdogs-keycloak-secret + - name: KC_CLIENTSECRET + valueFrom: + secretKeyRef: + key: password + name: cdogs-keycloak-secret + envFrom: + - configMapRef: + name: cdogs-keycloak-config + - configMapRef: + name: cdogs-server-config + test: false + triggers: + - type: ConfigChange + - imageChangeParams: + automatic: true + containerNames: + - "${APP_NAME}-app-${JOB_NAME}" + from: + kind: ImageStreamTag + name: "${REPO_NAME}-app:${JOB_NAME}" + namespace: "${NAMESPACE}" + type: ImageChange + - apiVersion: v1 + kind: Service + metadata: + annotations: + openshift.io/generated-by: OpenShiftNewApp + name: "${APP_NAME}-app-${JOB_NAME}" + spec: + ports: + - name: 3000-tcp + port: 3000 + protocol: TCP + targetPort: 3000 + selector: + app: "${APP_NAME}-${JOB_NAME}" + deploymentconfig: "${APP_NAME}-app-${JOB_NAME}" + - apiVersion: v1 + kind: Route + metadata: + annotations: + openshift.io/host.generated: "true" name: "${APP_NAME}-app-${JOB_NAME}" - weight: 100 - wildcardPolicy: None + spec: + host: "${HOST_ROUTE}" + path: / + port: + targetPort: 3000-tcp + tls: + insecureEdgeTerminationPolicy: Redirect + termination: edge + to: + kind: Service + name: "${APP_NAME}-app-${JOB_NAME}" + weight: 100 + wildcardPolicy: None parameters: -- name: REPO_NAME - description: Application repository name - displayName: Repository Name - required: true -- name: JOB_NAME - description: Job identifier (i.e. 'pr-5' OR 'master') - displayName: Job Branch Name - required: true -- name: NAMESPACE - description: Target namespace reference (i.e. '9f0fbe-dev') - displayName: Target Namespace - required: true -- name: APP_NAME - description: Application name - displayName: Application name - required: true -- name: HOST_ROUTE - description: The host the route will use to expose service outside cluster - displayName: Host route - required: true + - name: REPO_NAME + description: Application repository name + displayName: Repository Name + required: true + - name: JOB_NAME + description: Job identifier (i.e. 'pr-5' OR 'master') + displayName: Job Branch Name + required: true + - name: NAMESPACE + description: Target namespace reference (i.e. '9f0fbe-dev') + displayName: Target Namespace + required: true + - name: APP_NAME + description: Application name + displayName: Application name + required: true + - name: HOST_ROUTE + description: The host the route will use to expose service outside cluster + displayName: Host route + required: true