From 32de04ebf06c72242240c98ef5f5a40f0f605745 Mon Sep 17 00:00:00 2001 From: NilsOveTen Date: Fri, 23 Dec 2022 14:21:58 +0100 Subject: [PATCH] chore: deploy with kustomize --- .github/workflows/deploy-staging.yaml | 15 ++-- .gitignore | 1 + Cargo.lock | 2 +- Cargo.toml | 2 +- Dockerfile | 8 +- README.md | 2 +- deploy/base/kustomization.yaml | 9 +++ .../service-fdk-dataset-event-publisher.yaml | 14 ++++ ...eployment-fdk-dataset-event-publisher.yaml | 80 +++++++++++++++++++ deploy/demo/kustomization.yaml | 7 ++ ...eployment-fdk-dataset-event-publisher.yaml | 80 +++++++++++++++++++ deploy/prod/kustomization.yaml | 7 ++ ...eployment-fdk-dataset-event-publisher.yaml | 80 +++++++++++++++++++ deploy/staging/kustomization.yaml | 7 ++ src/bin/fdk-dataset-event-publisher.rs | 2 +- 15 files changed, 303 insertions(+), 13 deletions(-) create mode 100644 deploy/base/kustomization.yaml create mode 100644 deploy/base/service-fdk-dataset-event-publisher.yaml create mode 100644 deploy/demo/deployment-fdk-dataset-event-publisher.yaml create mode 100644 deploy/demo/kustomization.yaml create mode 100644 deploy/prod/deployment-fdk-dataset-event-publisher.yaml create mode 100644 deploy/prod/kustomization.yaml create mode 100644 deploy/staging/deployment-fdk-dataset-event-publisher.yaml create mode 100644 deploy/staging/kustomization.yaml diff --git a/.github/workflows/deploy-staging.yaml b/.github/workflows/deploy-staging.yaml index 53cfb83..0751591 100644 --- a/.github/workflows/deploy-staging.yaml +++ b/.github/workflows/deploy-staging.yaml @@ -14,24 +14,27 @@ jobs: secrets: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - build: - name: Build with reusable workflow when pull request is created + build-dataset: + name: Build dataset-event-publisher when pull request is created if: github.event.pull_request.draft == false uses: Informasjonsforvaltning/workflows/.github/workflows/build-push.yaml@main with: app_name: fdk-dataset-event-publisher environment: staging + build_env: true + build_env_name: BINARY + build_env_value: fdk-dataset-event-publisher secrets: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GCP_SA_DIGDIR_FDK_GCR_KEY: ${{ secrets.GCP_SA_DIGDIR_FDK_GCR_KEY }} deploy: - name: Deploy to staging environment with reusable workflow when test and build is successful + name: Deploy publishers to staging environment with reusable workflow if: github.event.pull_request.draft == false - needs: [test, build] - uses: Informasjonsforvaltning/workflows/.github/workflows/deploy.yaml@main + needs: [test, build-dataset] + uses: Informasjonsforvaltning/workflows/.github/workflows/kustomize-deploy.yaml@main with: - app_name: fdk-dataset-event-publisher + app_name: fdk-kafka-event-publisher environment: staging cluster: digdir-fdk-dev secrets: diff --git a/.gitignore b/.gitignore index ea8c4bf..3a8cabc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.idea diff --git a/Cargo.lock b/Cargo.lock index e946beb..c8883eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -777,7 +777,7 @@ dependencies = [ ] [[package]] -name = "fdk-event-publisher" +name = "fdk-kafka-event-publisher" version = "0.1.0" dependencies = [ "actix-web", diff --git a/Cargo.toml b/Cargo.toml index bceb6b8..18bcca7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "fdk-event-publisher" +name = "fdk-kafka-event-publisher" version = "0.1.0" edition = "2021" diff --git a/Dockerfile b/Dockerfile index 71a00ed..e059f08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ clang COPY ./ ./ -RUN cargo build --release +ARG BINARY +RUN cargo build --release --bin ${BINARY} FROM debian:bookworm-slim @@ -20,6 +21,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ ENV TZ=Europe/Oslo RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -COPY --from=builder /build/target/release/fdk-dataset-event-publisher /fdk-dataset-event-publisher +ARG BINARY +COPY --from=builder /build/target/release/${BINARY} /release -CMD ["/fdk-dataset-event-publisher"] +CMD ["/release"] diff --git a/README.md b/README.md index 5aa70ae..0760f0f 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# fdk-dataset-event-publisher +# fdk-kafka-event-publisher diff --git a/deploy/base/kustomization.yaml b/deploy/base/kustomization.yaml new file mode 100644 index 0000000..7bdef94 --- /dev/null +++ b/deploy/base/kustomization.yaml @@ -0,0 +1,9 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - service-fdk-dataset-event-publisher.yaml +images: + - name: fdk-dataset-event-publisher + newName: eu.gcr.io/digdir-fdk-infra/fdk-dataset-event-publisher + newTag: $(GIT_COMMIT_SHA) diff --git a/deploy/base/service-fdk-dataset-event-publisher.yaml b/deploy/base/service-fdk-dataset-event-publisher.yaml new file mode 100644 index 0000000..3dac6a9 --- /dev/null +++ b/deploy/base/service-fdk-dataset-event-publisher.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: fdk-dataset-event-publisher +spec: + selector: + fdk.service: fdk-dataset-event-publisher + ports: + - name: http + protocol: TCP + port: 8080 + targetPort: 8081 + type: NodePort diff --git a/deploy/demo/deployment-fdk-dataset-event-publisher.yaml b/deploy/demo/deployment-fdk-dataset-event-publisher.yaml new file mode 100644 index 0000000..cd7aa43 --- /dev/null +++ b/deploy/demo/deployment-fdk-dataset-event-publisher.yaml @@ -0,0 +1,80 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: fdk-dataset-event-publisher + labels: + fdk.service: fdk-dataset-event-publisher +spec: + replicas: 1 + selector: + matchLabels: + fdk.service: fdk-dataset-event-publisher + strategy: + type: RollingUpdate + template: + metadata: + labels: + fdk.service: fdk-dataset-event-publisher + annotations: + prometheus.io/scrape: "true" + spec: + containers: + - env: + - name: SCHEMA_REGISTRY + valueFrom: + secretKeyRef: + name: fdk-metadata-quality-demo + key: SCHEMA_REGISTRY + - name: BROKERS + valueFrom: + secretKeyRef: + name: fdk-metadata-quality-demo + key: BROKERS + - name: RABBITMQ_USERNAME + valueFrom: + secretKeyRef: + name: rabbitmq-demo + key: RABBITMQ_USERNAME + - name: RABBITMQ_PASSWORD + valueFrom: + secretKeyRef: + name: rabbitmq-demo + key: RABBITMQ_PASSWORD + - name: RABBITMQ_HOST + valueFrom: + secretKeyRef: + name: rabbitmq-demo + key: RABBITMQ_HOST + - name: RABBITMQ_PORT + valueFrom: + secretKeyRef: + name: rabbitmq-demo + key: RABBITMQ_PORT + - name: HARVESTER_API_URL + valueFrom: + secretKeyRef: + name: commonurl-demo + key: FDK_DATASET_HARVESTER_URI + - name: REASONING_API_URL + valueFrom: + secretKeyRef: + name: commonurl-demo + key: FDK_REASONING_SERVICE_URI + name: fdk-dataset-event-publisher + image: eu.gcr.io/digdir-fdk-infra/fdk-dataset-event-publisher:$(GIT_COMMIT_SHA) + imagePullPolicy: Always + ports: + - containerPort: 8080 + resources: + requests: + memory: "500Mi" + livenessProbe: + exec: + command: + - "true" + readinessProbe: + exec: + command: + - "true" + restartPolicy: Always diff --git a/deploy/demo/kustomization.yaml b/deploy/demo/kustomization.yaml new file mode 100644 index 0000000..ebf6ae1 --- /dev/null +++ b/deploy/demo/kustomization.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: demo +resources: + - deployment-fdk-dataset-event-publisher.yaml + - ../base diff --git a/deploy/prod/deployment-fdk-dataset-event-publisher.yaml b/deploy/prod/deployment-fdk-dataset-event-publisher.yaml new file mode 100644 index 0000000..ea64bc7 --- /dev/null +++ b/deploy/prod/deployment-fdk-dataset-event-publisher.yaml @@ -0,0 +1,80 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: fdk-dataset-event-publisher + labels: + fdk.service: fdk-dataset-event-publisher +spec: + replicas: 1 + selector: + matchLabels: + fdk.service: fdk-dataset-event-publisher + strategy: + type: RollingUpdate + template: + metadata: + labels: + fdk.service: fdk-dataset-event-publisher + annotations: + prometheus.io/scrape: "true" + spec: + containers: + - env: + - name: SCHEMA_REGISTRY + valueFrom: + secretKeyRef: + name: fdk-metadata-quality-prod + key: SCHEMA_REGISTRY + - name: BROKERS + valueFrom: + secretKeyRef: + name: fdk-metadata-quality-prod + key: BROKERS + - name: RABBITMQ_USERNAME + valueFrom: + secretKeyRef: + name: rabbitmq-prod + key: RABBITMQ_USERNAME + - name: RABBITMQ_PASSWORD + valueFrom: + secretKeyRef: + name: rabbitmq-prod + key: RABBITMQ_PASSWORD + - name: RABBITMQ_HOST + valueFrom: + secretKeyRef: + name: rabbitmq-prod + key: RABBITMQ_HOST + - name: RABBITMQ_PORT + valueFrom: + secretKeyRef: + name: rabbitmq-prod + key: RABBITMQ_PORT + - name: HARVESTER_API_URL + valueFrom: + secretKeyRef: + name: commonurl-prod + key: FDK_DATASET_HARVESTER_URI + - name: REASONING_API_URL + valueFrom: + secretKeyRef: + name: commonurl-prod + key: FDK_REASONING_SERVICE_URI + name: fdk-dataset-event-publisher + image: eu.gcr.io/digdir-fdk-infra/fdk-dataset-event-publisher:$(GIT_COMMIT_SHA) + imagePullPolicy: Always + ports: + - containerPort: 8080 + resources: + requests: + memory: "500Mi" + livenessProbe: + exec: + command: + - "true" + readinessProbe: + exec: + command: + - "true" + restartPolicy: Always diff --git a/deploy/prod/kustomization.yaml b/deploy/prod/kustomization.yaml new file mode 100644 index 0000000..f566558 --- /dev/null +++ b/deploy/prod/kustomization.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: prod +resources: + - deployment-fdk-dataset-event-publisher.yaml + - ../base diff --git a/deploy/staging/deployment-fdk-dataset-event-publisher.yaml b/deploy/staging/deployment-fdk-dataset-event-publisher.yaml new file mode 100644 index 0000000..381f25e --- /dev/null +++ b/deploy/staging/deployment-fdk-dataset-event-publisher.yaml @@ -0,0 +1,80 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: fdk-dataset-event-publisher + labels: + fdk.service: fdk-dataset-event-publisher +spec: + replicas: 1 + selector: + matchLabels: + fdk.service: fdk-dataset-event-publisher + strategy: + type: RollingUpdate + template: + metadata: + labels: + fdk.service: fdk-dataset-event-publisher + annotations: + prometheus.io/scrape: "true" + spec: + containers: + - env: + - name: SCHEMA_REGISTRY + valueFrom: + secretKeyRef: + name: fdk-metadata-quality-staging + key: SCHEMA_REGISTRY + - name: BROKERS + valueFrom: + secretKeyRef: + name: fdk-metadata-quality-staging + key: BROKERS + - name: RABBITMQ_USERNAME + valueFrom: + secretKeyRef: + name: rabbitmq-staging + key: RABBITMQ_USERNAME + - name: RABBITMQ_PASSWORD + valueFrom: + secretKeyRef: + name: rabbitmq-staging + key: RABBITMQ_PASSWORD + - name: RABBITMQ_HOST + valueFrom: + secretKeyRef: + name: rabbitmq-staging + key: RABBITMQ_HOST + - name: RABBITMQ_PORT + valueFrom: + secretKeyRef: + name: rabbitmq-staging + key: RABBITMQ_PORT + - name: HARVESTER_API_URL + valueFrom: + secretKeyRef: + name: commonurl-staging + key: FDK_DATASET_HARVESTER_URI + - name: REASONING_API_URL + valueFrom: + secretKeyRef: + name: commonurl-staging + key: FDK_REASONING_SERVICE_URI + name: fdk-dataset-event-publisher + image: eu.gcr.io/digdir-fdk-infra/fdk-dataset-event-publisher:$(GIT_COMMIT_SHA) + imagePullPolicy: Always + ports: + - containerPort: 8080 + resources: + requests: + memory: "500Mi" + livenessProbe: + exec: + command: + - "true" + readinessProbe: + exec: + command: + - "true" + restartPolicy: Always diff --git a/deploy/staging/kustomization.yaml b/deploy/staging/kustomization.yaml new file mode 100644 index 0000000..e88764b --- /dev/null +++ b/deploy/staging/kustomization.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: staging +resources: + - deployment-fdk-dataset-event-publisher.yaml + - ../base diff --git a/src/bin/fdk-dataset-event-publisher.rs b/src/bin/fdk-dataset-event-publisher.rs index 2903e49..8f7af49 100644 --- a/src/bin/fdk-dataset-event-publisher.rs +++ b/src/bin/fdk-dataset-event-publisher.rs @@ -4,7 +4,7 @@ use async_trait::async_trait; use lazy_static::lazy_static; use serde_derive::Serialize; -use fdk_event_publisher::{ +use fdk_kafka_event_publisher::{ error::Error, kafka, run_event_publisher, utils::http_get, ChangeType, EventConfig, Resource, ResourceConfig, };