diff --git a/docker-compose.yml b/docker-compose.yml index 0949255..7da8b2e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,10 @@ --- services: app: - image: node:18-slim build: context: ./src/app dockerfile: Dockerfile + target: environment working_dir: /usr/local/src environment: - PORT=4321 diff --git a/helm-chart/templates/frontend/deployment.yaml b/helm-chart/templates/frontend/deployment.yaml new file mode 100644 index 0000000..e7235ef --- /dev/null +++ b/helm-chart/templates/frontend/deployment.yaml @@ -0,0 +1,57 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "third-places.fullname" . }}-frontend + labels: + {{- include "third-places.labels" . | nindent 4 }} + app.kubernetes.io/component: frontend +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "third-places.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: frontend + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "third-places.selectorLabels" . | nindent 8 }} + app.kubernetes.io/component: frontend + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }}-frontend + image: "{{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.frontend.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/helm-chart/templates/frontend/service.yaml b/helm-chart/templates/frontend/service.yaml new file mode 100644 index 0000000..be0a8e0 --- /dev/null +++ b/helm-chart/templates/frontend/service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "third-places.fullname" . }}-frontend + labels: + {{- include "third-places.labels" . | nindent 4 }} + app.kubernetes.io/component: frontend +spec: + type: ClusterIP + ports: + - port: 80 + targetPort: http + protocol: TCP + name: http + selector: + {{- include "third-places.selectorLabels" . | nindent 4 }} + app.kubernetes.io/component: frontend diff --git a/helm-chart/templates/ingress.yaml b/helm-chart/templates/ingress.yaml index 44b1b3d..85c2302 100644 --- a/helm-chart/templates/ingress.yaml +++ b/helm-chart/templates/ingress.yaml @@ -1,6 +1,5 @@ {{- if .Values.ingress.enabled -}} {{- $fullName := include "third-places.fullname" . -}} -{{- $svcPort := .Values.service.port -}} apiVersion: networking.k8s.io/v1 kind: Ingress metadata: @@ -33,12 +32,26 @@ spec: paths: {{- range .paths }} - path: {{ . }} + pathType: Prefix + backend: + service: + name: {{ $fullName }}-frontend + port: + name: http + - path: {{ . | trimSuffix "/" }}/api/ + pathType: Prefix + backend: + service: + name: {{ $fullName }} + port: + name: http + - path: {{ . | trimSuffix "/" }}/admin/ pathType: Prefix backend: service: name: {{ $fullName }} port: - number: {{ $svcPort }} + name: http {{- end }} {{- end }} {{- end }} diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml index 582cb53..a1a37eb 100644 --- a/helm-chart/values.yaml +++ b/helm-chart/values.yaml @@ -54,6 +54,13 @@ tolerations: [] affinity: {} +frontend: + image: + repository: ghcr.io/codeforphilly/third-places/frontend + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: 0.1.2 + postgresql: image: repository: postgis/postgis diff --git a/src/app/Dockerfile b/src/app/Dockerfile index 7579870..cb8a535 100644 --- a/src/app/Dockerfile +++ b/src/app/Dockerfile @@ -1,11 +1,30 @@ -FROM node:18-slim -ARG HOME=usr/local/src/ -WORKDIR $HOME +## Target: environment +# +# This initially-empty target provides an environment for docker-compose +# to start from the same base as the production builder environment. Common +# dependencies could be added here +# +FROM node:18-slim as environment -COPY entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh -ADD . . -ENTRYPOINT [ "/entrypoint.sh" ] -CMD ["npm", "run", "dev", "--host"] -EXPOSE 4321 \ No newline at end of file +## Target: builder +# +# This target builds /src/dist with layers optimized for caching dependencies +# +FROM environment as builder +WORKDIR /src + +COPY package*.json ./ +RUN npm ci + +COPY * ./ +RUN npm run build + + +## Target: runtime +# +# This target provides an nginx web server wrapped around the static +# website build from the builder target +# +FROM nginx:alpine as runtime +COPY --from=builder /src/dist /usr/share/nginx/html