From bb37728e3ae48541c321a576ecc4ba2a9268c21b Mon Sep 17 00:00:00 2001 From: Bruno Wu Date: Thu, 12 Oct 2023 11:07:51 +0100 Subject: [PATCH] ZIL-5408: Dockerise PDT (#218) * Dockerise PDT * Update workflow and makefile * Update Apt and workdir * Remove libssl-dev on image * Update dockerfile and add deployment config * Update dockerfile to accommodate all warnings * update cicd * Migrate to Kustomize * Remove ingress and svc * Remove PV, certificates and ingress * Remove pv references --- .github/workflows/cicd-stg.yml | 3 +++ products/pdt/.dockerignore | 6 +++++ products/pdt/Cargo.lock | 21 +++++++++++---- products/pdt/Dockerfile | 27 +++++++++++++++++++ products/pdt/Makefile | 13 +++++++++ products/pdt/cd/base/deployment.yaml | 24 +++++++++++++++++ products/pdt/cd/base/kustomization.yaml | 6 +++++ products/pdt/cd/base/namespace.yaml | 4 +++ products/pdt/cd/base/pvc.yaml | 11 ++++++++ .../cd/overlays/staging/kustomization.yaml | 7 +++++ products/pdt/docker-compose.yaml | 16 +++++++++++ products/pdt/pdt/Cargo.toml | 1 + products/pdt/pdt/src/main.rs | 6 +++++ 13 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 products/pdt/.dockerignore create mode 100644 products/pdt/Dockerfile create mode 100644 products/pdt/Makefile create mode 100644 products/pdt/cd/base/deployment.yaml create mode 100644 products/pdt/cd/base/kustomization.yaml create mode 100644 products/pdt/cd/base/namespace.yaml create mode 100644 products/pdt/cd/base/pvc.yaml create mode 100644 products/pdt/cd/overlays/staging/kustomization.yaml create mode 100644 products/pdt/docker-compose.yaml diff --git a/.github/workflows/cicd-stg.yml b/.github/workflows/cicd-stg.yml index 1144f3d31..2b6e83d7a 100644 --- a/.github/workflows/cicd-stg.yml +++ b/.github/workflows/cicd-stg.yml @@ -38,6 +38,9 @@ jobs: - application: neo-savant image_name: neo-savant path: products/neo-savant + - application: pdt + image_name: pdt + path: products/pdt env: DOCKER_DOMAIN: asia-docker.pkg.dev REGISTRY: asia-docker.pkg.dev/prj-d-devops-services-4dgwlsse/zilliqa-public diff --git a/products/pdt/.dockerignore b/products/pdt/.dockerignore new file mode 100644 index 000000000..130e74d72 --- /dev/null +++ b/products/pdt/.dockerignore @@ -0,0 +1,6 @@ +target/ +.vscode/ +# Target for downloaded files +downloads/ +# Stores download metadata +meta.json diff --git a/products/pdt/Cargo.lock b/products/pdt/Cargo.lock index c425a4911..d379ea9b5 100644 --- a/products/pdt/Cargo.lock +++ b/products/pdt/Cargo.lock @@ -2946,11 +2946,11 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.55" +version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.3.3", "cfg-if", "foreign-types", "libc", @@ -2976,14 +2976,24 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "300.1.5+3.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "559068e4c12950d7dcaa1857a61725c0d38d4fc03ff8e070ab31a75d6e316491" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" -version = "0.9.90" +version = "0.9.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6" +checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" dependencies = [ "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] @@ -3102,6 +3112,7 @@ dependencies = [ "async-trait", "clap", "futures", + "openssl", "pdtbq", "pdtdb", "pdtlib", diff --git a/products/pdt/Dockerfile b/products/pdt/Dockerfile new file mode 100644 index 000000000..f9711f3e8 --- /dev/null +++ b/products/pdt/Dockerfile @@ -0,0 +1,27 @@ +# Requires alpine to get openssl and build +FROM rust:1.71.0-bullseye as builder + +WORKDIR /pdt + +RUN apt-get update -y && \ + apt-get upgrade -y && \ + apt-get install -y --no-install-recommends protobuf-compiler=3.12.4-1+deb11u1 build-essential=12.9 cmake=3.18.4-2+deb11u1 + +RUN mkdir build + +COPY . . + +RUN --mount=type=cache,target=/usr/local/cargo/registry cargo build && \ + mv /pdt/target/debug/pdt /pdt/build/ + +FROM debian:bullseye-slim + +RUN apt-get update -y && \ + apt-get upgrade -y && \ + apt-get install -y --no-install-recommends ca-certificates=20210119 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +COPY --from=builder /pdt/build/pdt /pdt + +CMD ["/pdt", "test"] diff --git a/products/pdt/Makefile b/products/pdt/Makefile new file mode 100644 index 000000000..2fd64e1d9 --- /dev/null +++ b/products/pdt/Makefile @@ -0,0 +1,13 @@ +.PHONY: all +all: image/build-and-push + +.ONESHELL: +SHELL := /bin/bash +.SHELLFLAGS = -ec + +IMAGE_TAG ?= localhost:5001/pdt:latest + +## Build and push the Docker image +image/build-and-push: + docker build -t "${IMAGE_TAG}" . + docker push "${IMAGE_TAG}" diff --git a/products/pdt/cd/base/deployment.yaml b/products/pdt/cd/base/deployment.yaml new file mode 100644 index 000000000..c6c3fb462 --- /dev/null +++ b/products/pdt/cd/base/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: pdt + namespace: pdt + labels: + "app.kubernetes.io/name": "pdt" +spec: + replicas: 1 + selector: + matchLabels: + "app.kubernetes.io/name": "pdt" + strategy: + type: RollingUpdate + template: + metadata: + labels: + "app.kubernetes.io/name": "pdt" + spec: + containers: + - image: pdt + name: pdt + ports: + - containerPort: 80 diff --git a/products/pdt/cd/base/kustomization.yaml b/products/pdt/cd/base/kustomization.yaml new file mode 100644 index 000000000..918bacd79 --- /dev/null +++ b/products/pdt/cd/base/kustomization.yaml @@ -0,0 +1,6 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - namespace.yaml + - pvc.yaml + - deployment.yaml diff --git a/products/pdt/cd/base/namespace.yaml b/products/pdt/cd/base/namespace.yaml new file mode 100644 index 000000000..9e7010d2f --- /dev/null +++ b/products/pdt/cd/base/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: pdt diff --git a/products/pdt/cd/base/pvc.yaml b/products/pdt/cd/base/pvc.yaml new file mode 100644 index 000000000..51d592fed --- /dev/null +++ b/products/pdt/cd/base/pvc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: pdt-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 128Gi + storageClassName: standard diff --git a/products/pdt/cd/overlays/staging/kustomization.yaml b/products/pdt/cd/overlays/staging/kustomization.yaml new file mode 100644 index 000000000..42973cf3d --- /dev/null +++ b/products/pdt/cd/overlays/staging/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - ../../base + +namespace: pdt-staging diff --git a/products/pdt/docker-compose.yaml b/products/pdt/docker-compose.yaml new file mode 100644 index 000000000..ed8c9bcf6 --- /dev/null +++ b/products/pdt/docker-compose.yaml @@ -0,0 +1,16 @@ +version: "3" +services: + pdt: + environment: + RUST_BACKTRACE: 1 + build: + context: . + dockerfile: Dockerfile + container_name: pdt + volumes: + - "download_data:/var/download_data" + command: + - /pdt + - test +volumes: + download_data: diff --git a/products/pdt/pdt/Cargo.toml b/products/pdt/pdt/Cargo.toml index f95c149ab..ab91b9b06 100644 --- a/products/pdt/pdt/Cargo.toml +++ b/products/pdt/pdt/Cargo.toml @@ -12,6 +12,7 @@ pdtdb = { path = "../pdtdb" } pdtpsql = { path = "../pdtpsql" } pdtparse = { path = "../pdtparse" } pdtlisten = { path = "../pdtlisten" } +openssl = { version = "0.10.57", features = ["vendored"] } tokio = { version = "1.28.1", features = [ "macros", "rt-multi-thread", diff --git a/products/pdt/pdt/src/main.rs b/products/pdt/pdt/src/main.rs index aa0413415..c42a6d087 100644 --- a/products/pdt/pdt/src/main.rs +++ b/products/pdt/pdt/src/main.rs @@ -69,6 +69,8 @@ enum Commands { ParseEvents, #[command(name = "listen")] Listen(ListenOptions), + #[command(name = "test")] + Test, } // #[derive(Debug, Args)] @@ -364,5 +366,9 @@ async fn main() -> Result<()> { ) .await } + Commands::Test => { + println!("Hello World"); + loop {} + } } }