diff --git a/Dockerfile b/Dockerfile index adb7f39d..d1beb17e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ COPY ./src/frontend/packages/eslint-config-impress/package.json ./packages/eslin RUN yarn --frozen-lockfile ### ---- Front-end builder image ---- -FROM node:20 as frontend-builder +FROM node:20 as frontend-builder-1 WORKDIR /builder @@ -34,6 +34,8 @@ COPY ./src/frontend . WORKDIR /builder/apps/impress +FROM frontend-builder-1 as frontend-builder-2 + RUN yarn build @@ -44,7 +46,7 @@ FROM nginxinc/nginx-unprivileged:1.25 as frontend-production ARG DOCKER_USER USER ${DOCKER_USER} -COPY --from=frontend-builder \ +COPY --from=frontend-builder-2 \ /builder/apps/impress/out \ /usr/share/nginx/html @@ -83,7 +85,7 @@ RUN yarn install --frozen-lockfile && \ # ---- static link collector ---- FROM base as link-collector -ARG PEOPLE_STATIC_ROOT=/data/static +ARG IMPRESS_STATIC_ROOT=/data/static # Install libpangocairo & rdfind RUN apt-get update && \ diff --git a/Tiltfile b/Tiltfile new file mode 100644 index 00000000..21aaca3a --- /dev/null +++ b/Tiltfile @@ -0,0 +1,71 @@ +load('ext://uibutton', 'cmd_button', 'bool_input', 'location') +load('ext://namespace', 'namespace_create', 'namespace_inject') +namespace_create('impress') + +docker_build( + 'localhost:5001/impress-backend:latest', + context='.', + dockerfile='./Dockerfile', + only=['./src/backend', './src/mail', './docker'], + target = 'backend-development', + live_update=[ + sync('./src/backend', '/app'), + run( + 'pip install -r /app/requirements.txt', + trigger=['./api/requirements.txt'] + ) + ] +) + +docker_build( + 'localhost:5001/impress-frontend:latest', + context='.', + dockerfile='./Dockerfile', + build_args={'ENV': 'dev'}, + only=['./src/frontend', './src/mail', './docker'], + target = 'frontend-builder-1', + live_update=[ + sync('./src/frontend', '/builder'), + ] +) + +k8s_yaml(local('cd src/helm && helmfile -n impress -e dev template .')) + +migration = ''' +set -eu +# get k8s pod name from tilt resource name +POD_NAME="$(tilt get kubernetesdiscovery impress-backend -ojsonpath='{.status.pods[0].name}')" +kubectl -n impress exec "$POD_NAME" -- python manage.py makemigrations +''' +cmd_button('Make migration', + argv=['sh', '-c', migration], + resource='impress-backend', + icon_name='developer_board', + text='Run makemigration', +) + +pod_migrate = ''' +set -eu +# get k8s pod name from tilt resource name +POD_NAME="$(tilt get kubernetesdiscovery impress-backend -ojsonpath='{.status.pods[0].name}')" +kubectl -n impress exec "$POD_NAME" -- python manage.py migrate --no-input +''' +cmd_button('Migrate db', + argv=['sh', '-c', pod_migrate], + resource='impress-backend', + icon_name='developer_board', + text='Run database migration', +) + +pod_add_admin = ''' +set -eu +# get k8s pod name from tilt resource name +POD_NAME="$(tilt get kubernetesdiscovery impress-backend -ojsonpath='{.status.pods[0].name}')" +kubectl -n impress exec "$POD_NAME" -- python manage.py createsuperuser --email admin@example.com --password admin +''' +cmd_button('Add admin', + argv=['sh', '-c', pod_add_admin], + resource='impress-backend', + icon_name='developer_board', + text='Create superadmin', +) diff --git a/src/frontend/apps/impress/.env.dev b/src/frontend/apps/impress/.env.dev new file mode 100644 index 00000000..8a7f521d --- /dev/null +++ b/src/frontend/apps/impress/.env.dev @@ -0,0 +1 @@ +NEXT_PUBLIC_API_URL=https://impress.127.0.0.1.nip.io/api/v1.0/ diff --git a/src/helm/env.d/dev/values.impress.yaml.gotmpl b/src/helm/env.d/dev/values.impress.yaml.gotmpl index 260738c9..98a881b2 100644 --- a/src/helm/env.d/dev/values.impress.yaml.gotmpl +++ b/src/helm/env.d/dev/values.impress.yaml.gotmpl @@ -4,6 +4,7 @@ image: tag: "latest" backend: + replicas: 1 envVars: DJANGO_CSRF_TRUSTED_ORIGINS: https://impress.127.0.0.1.nip.io,http://impress.127.0.0.1.nip.io DJANGO_CONFIGURATION: Production @@ -38,6 +39,15 @@ backend: REDIS_URL: redis://default:pass@redis-master:6379/1 frontend: + envVars: + PORT: 8080 + NEXT_PUBLIC_API_URL: https://impress.127.0.0.1.nip.io/api/v1.0/ + + replicas: 1 + command: + - yarn + - dev + image: repository: localhost:5001/impress-frontend pullPolicy: Always diff --git a/src/helm/helmfile.yaml b/src/helm/helmfile.yaml index c2ed6314..35a94ff9 100644 --- a/src/helm/helmfile.yaml +++ b/src/helm/helmfile.yaml @@ -26,6 +26,7 @@ releases: values: - auth: password: pass + architecture: standalone - name: extra installed: {{ ne .Environment.Name "dev" | toYaml }} diff --git a/src/helm/impress/templates/backend_deployment.yaml b/src/helm/impress/templates/backend_deployment.yaml index eec6bc39..d0c0f086 100644 --- a/src/helm/impress/templates/backend_deployment.yaml +++ b/src/helm/impress/templates/backend_deployment.yaml @@ -5,6 +5,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ $fullName }} + namespace: {{ .Release.Namespace | quote }} labels: {{- include "impress.common.labels" (list . $component) | nindent 4 }} spec: diff --git a/src/helm/impress/templates/backend_job.yaml b/src/helm/impress/templates/backend_job.yaml index 5be5d556..f55447ae 100644 --- a/src/helm/impress/templates/backend_job.yaml +++ b/src/helm/impress/templates/backend_job.yaml @@ -5,6 +5,7 @@ apiVersion: batch/v1 kind: Job metadata: name: {{ $fullName }}-migrate + namespace: {{ .Release.Namespace | quote }} {{- with .Values.backend.migrateJobAnnotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/src/helm/impress/templates/backend_svc.yaml b/src/helm/impress/templates/backend_svc.yaml index a80997aa..579bdbf6 100644 --- a/src/helm/impress/templates/backend_svc.yaml +++ b/src/helm/impress/templates/backend_svc.yaml @@ -5,6 +5,7 @@ apiVersion: v1 kind: Service metadata: name: {{ $fullName }} + namespace: {{ .Release.Namespace | quote }} labels: {{- include "impress.common.labels" (list . $component) | nindent 4 }} annotations: diff --git a/src/helm/impress/templates/frontend_deployment.yaml b/src/helm/impress/templates/frontend_deployment.yaml index 4407f79a..959ab02a 100644 --- a/src/helm/impress/templates/frontend_deployment.yaml +++ b/src/helm/impress/templates/frontend_deployment.yaml @@ -5,6 +5,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ $fullName }} + namespace: {{ .Release.Namespace | quote }} labels: {{- include "impress.common.labels" (list . $component) | nindent 4 }} spec: diff --git a/src/helm/impress/templates/frontend_svc.yaml b/src/helm/impress/templates/frontend_svc.yaml index e6bbff18..ac42e4c6 100644 --- a/src/helm/impress/templates/frontend_svc.yaml +++ b/src/helm/impress/templates/frontend_svc.yaml @@ -5,6 +5,7 @@ apiVersion: v1 kind: Service metadata: name: {{ $fullName }} + namespace: {{ .Release.Namespace | quote }} labels: {{- include "impress.common.labels" (list . $component) | nindent 4 }} annotations: diff --git a/src/helm/impress/templates/ingress.yaml b/src/helm/impress/templates/ingress.yaml index 9a551876..aecc5977 100644 --- a/src/helm/impress/templates/ingress.yaml +++ b/src/helm/impress/templates/ingress.yaml @@ -15,6 +15,7 @@ apiVersion: extensions/v1beta1 kind: Ingress metadata: name: {{ $fullName }} + namespace: {{ .Release.Namespace | quote }} labels: {{- include "impress.labels" . | nindent 4 }} {{- with .Values.ingress.annotations }} diff --git a/src/helm/impress/templates/ingress_admin.yaml b/src/helm/impress/templates/ingress_admin.yaml index 70e9ca24..64532389 100644 --- a/src/helm/impress/templates/ingress_admin.yaml +++ b/src/helm/impress/templates/ingress_admin.yaml @@ -15,6 +15,7 @@ apiVersion: extensions/v1beta1 kind: Ingress metadata: name: {{ $fullName }}-admin + namespace: {{ .Release.Namespace | quote }} labels: {{- include "impress.labels" . | nindent 4 }} {{- with .Values.ingressAdmin.annotations }} diff --git a/start-kind.sh b/start-kind.sh new file mode 100644 index 00000000..a77f12f6 --- /dev/null +++ b/start-kind.sh @@ -0,0 +1,103 @@ +#!/bin/sh +set -o errexit + +CURRENT_DIR=$(pwd) + +echo "0. Create ca" +# 0. Create ca +mkcert -install +cd /tmp +mkcert "127.0.0.1.nip.io" "*.127.0.0.1.nip.io" +cd $CURRENT_DIR + +echo "1. Create registry container unless it already exists" +# 1. Create registry container unless it already exists +reg_name='kind-registry' +reg_port='5001' +if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then + docker run \ + -d --restart=always -p "127.0.0.1:${reg_port}:5000" --network bridge --name "${reg_name}" \ + registry:2 +fi + +echo "2. Create kind cluster with containerd registry config dir enabled" +# 2. Create kind cluster with containerd registry config dir enabled +# TODO: kind will eventually enable this by default and this patch will +# be unnecessary. +# +# See: +# https://github.com/kubernetes-sigs/kind/issues/2875 +# https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration +# See: https://github.com/containerd/containerd/blob/main/docs/hosts.md +cat <