Skip to content

Commit

Permalink
updates to openshift deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
roblo-cgi committed Oct 19, 2022
1 parent 7ea2db1 commit b83da4e
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 38 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/deploy-to-openshift-dev.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 1 DEV - Deploy Backend
name: 1 DEV - Deploy Dynamics API

env:
# 🖊️ EDIT your repository secrets to log into your OpenShift cluster and set up the context.
Expand All @@ -21,10 +21,10 @@ env:
ARTIFACTORY_REPO: artifacts.developer.gov.bc.ca

APP_NAME: 'ccof'
REPO_NAME: "educ-ccof"
REPO_NAME: "educ-ccof-d365"
BRANCH: "main"
APP_NAME_BACKEND: "backend"
APP_FOLDER: "backend"
APP_NAME_BACKEND: "api-d365"

NAMESPACE: ${{ secrets.CCOF_NAMESPACE_NO_ENV }}
NAMESPACE_TOOLS: ${{ secrets.CCOF_NAMESPACE_NO_ENV }}-tools
COMMON_NAMESPACE: ${{ secrets.COMMON_NAMESPACE_NO_ENV }}
Expand Down Expand Up @@ -115,8 +115,8 @@ jobs:
# Or, perform a source-to-image build using https://github.com/redhat-actions/s2i-build
# Otherwise, point this to your Dockerfile/Containerfile relative to the repository root.
dockerfiles: |
./${{ env.APP_FOLDER }}/Dockerfile
context: ./${{ env.APP_FOLDER }}
./Dockerfile
context: ./

# https://github.com/redhat-actions/push-to-registry#readme
- name: Push backend to registry
Expand Down
5 changes: 3 additions & 2 deletions CCOF.Infrastructure.WebAPI/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ EXPOSE 5091
EXPOSE 5092

ENV ASPNETCORE_URLS=http://+:5091
ENV ASPNETCORE_ENVIRONMENT=Development

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser

FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
WORKDIR /src
WORKDIR /
COPY ["CCOF.Infrastructure.WebAPI/CCOF.Infrastructure.WebAPI.csproj", "CCOF.Infrastructure.WebAPI/"]
RUN dotnet restore "CCOF.Infrastructure.WebAPI/CCOF.Infrastructure.WebAPI.csproj"
COPY . .
WORKDIR "/src/CCOF.Infrastructure.WebAPI"
WORKDIR "/CCOF.Infrastructure.WebAPI"
RUN dotnet build "CCOF.Infrastructure.WebAPI.csproj" -c Release -o /app/build

FROM build AS publish
Expand Down
17 changes: 0 additions & 17 deletions docker-compose.debug.yml

This file was deleted.

13 changes: 0 additions & 13 deletions docker-compose.yml

This file was deleted.

186 changes: 186 additions & 0 deletions tools/openshift/backend.dc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
---
apiVersion: template.openshift.io/v1
kind: Template
labels:
template: "${REPO_NAME}-template"
metadata:
name: "${REPO_NAME}-backend-dc"
objects:
- apiVersion: v1
kind: DeploymentConfig
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
creationTimestamp:
labels:
app: "${APP_NAME}-${BRANCH}"
name: "${APP_NAME}-backend-${BRANCH}"
spec:
replicas: ${{MIN_REPLICAS}}
selector:
app: "${APP_NAME}-${BRANCH}"
deploymentconfig: "${APP_NAME}-backend-${BRANCH}"
strategy:
resources: {}
type: Rolling
template:
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
creationTimestamp:
labels:
app: "${APP_NAME}-${BRANCH}"
deploymentconfig: "${APP_NAME}-backend-${BRANCH}"
spec:
containers:
- image: image-registry.openshift-image-registry.svc:5000/${NAMESPACE}/${REPO_NAME}-backend-${BRANCH}:${TAG}
imagePullPolicy: Always
volumeMounts:
- name: tls-certs
mountPath: "/etc/tls-certs"
readOnly: true
- name: log-storage
mountPath: /logs
livenessProbe:
initialDelaySeconds: 20
failureThreshold: 5
httpGet:
path: "/api/health"
port: 8080
scheme: HTTP
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
name: "${APP_NAME}-backend-${BRANCH}"
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 443
protocol: TCP
envFrom:
- configMapRef:
name: educ-ccof-backend-config-map
readinessProbe:
initialDelaySeconds: 10
failureThreshold: 5
httpGet:
path: "/api/health"
port: 8080
scheme: HTTP
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
resources:
requests:
cpu: "${MIN_CPU}"
memory: "${MIN_MEM}"
limits:
cpu: "${MAX_CPU}"
memory: "${MAX_MEM}"
volumes:
- name: log-storage
emptyDir: {}
- name: tls-certs
secret:
secretName: ccof-backend-cert
test: false
triggers:
- type: ConfigChange
- apiVersion: v1
kind: Service
metadata:
annotations:
service.alpha.openshift.io/serving-cert-secret-name: "ccof-backend-cert"
openshift.io/generated-by: OpenShiftNewApp
creationTimestamp:
labels:
app: "${APP_NAME}-${BRANCH}"
name: "${APP_NAME}-backend-${BRANCH}"
spec:
ports:
- name: 8080-tcp
port: 8080
protocol: TCP
targetPort: 8080
- name: 443-https
port: 443
protocol: TCP
targetPort: 443
selector:
app: "${APP_NAME}-${BRANCH}"
deploymentconfig: "${APP_NAME}-backend-${BRANCH}"
- apiVersion: v1
kind: Route
metadata:
annotations:
openshift.io/host.generated: 'true'
labels:
app: "${APP_NAME}-${BRANCH}"
name: "${APP_NAME}-backend-${BRANCH}"
spec:
host: "${HOST_ROUTE}"
path: /api
port:
targetPort: 8080-tcp
tls:
insecureEdgeTerminationPolicy: Redirect
termination: edge
to:
kind: Service
name: "${APP_NAME}-backend-${BRANCH}"
weight: 100
wildcardPolicy: None
- apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: "${APP_NAME}-backend-${BRANCH}-cpu-autoscaler"
spec:
scaleTargetRef:
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
name: "${APP_NAME}-backend-${BRANCH}"
subresource: scale
minReplicas: ${{MIN_REPLICAS}}
maxReplicas: ${{MAX_REPLICAS}}
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 90
parameters:
- name: REPO_NAME
description: Application repository name
required: true
- name: BRANCH
description: Job identifier (i.e. 'pr-5' OR 'master')
required: true
- name: NAMESPACE
description: Target namespace reference (i.e. 'k8vopl-dev')
required: true
- name: APP_NAME
description: Application name
required: true
- name: HOST_ROUTE
description: The host the route will use to expose service outside cluster
required: true
- name: TAG
description: The identifying tag for this specific deployment
required: true
- name: MIN_REPLICAS
description: The minimum amount of replicas
required: true
- name: MAX_REPLICAS
description: The maximum amount of replicas
required: true
- name: MIN_CPU
description: The minimum amount of cpu
required: true
- name: MAX_CPU
description: The maximum amount of cpu
required: true
- name: MIN_MEM
description: The minimum amount of memory
required: true
- name: MAX_MEM
description: The maximum amount of memory
required: true

0 comments on commit b83da4e

Please sign in to comment.