From c64d29e2f3ebcb3a9c91304d72bb6cd7509b8f9e Mon Sep 17 00:00:00 2001 From: Tullio Sebastiani Date: Fri, 13 Dec 2024 11:41:07 +0100 Subject: [PATCH] dockerfile compile script --- .github/workflows/docker-image.yml | 1 + containers/Dockerfile | 60 ------------------- .../{build.sh => compile_dockerfile.sh} | 3 + 3 files changed, 4 insertions(+), 60 deletions(-) delete mode 100644 containers/Dockerfile rename containers/{build.sh => compile_dockerfile.sh} (60%) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 956f8027..4fc329fe 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -13,6 +13,7 @@ jobs: - name: Build the Docker images if: startsWith(github.ref, 'refs/tags') run: | + ./containers/compile_dockerfile.sh docker build --no-cache -t quay.io/krkn-chaos/krkn containers/ --build-arg TAG=${GITHUB_REF#refs/tags/} docker tag quay.io/krkn-chaos/krkn quay.io/redhat-chaos/krkn docker tag quay.io/krkn-chaos/krkn quay.io/krkn-chaos/krkn:${GITHUB_REF#refs/tags/} diff --git a/containers/Dockerfile b/containers/Dockerfile deleted file mode 100644 index 3ee0e51c..00000000 --- a/containers/Dockerfile +++ /dev/null @@ -1,60 +0,0 @@ -# oc build -FROM golang:1.22.5 AS oc-build -RUN apt-get update && apt-get install -y --no-install-recommends libkrb5-dev -WORKDIR /tmp -RUN git clone --branch release-4.18 https://github.com/openshift/oc.git -WORKDIR /tmp/oc -RUN go mod edit -go 1.22.5 &&\ - go get github.com/moby/buildkit@v0.12.5 &&\ - go get github.com/containerd/containerd@v1.7.11&&\ - go get github.com/docker/docker@v25.0.6&&\ - go get github.com/opencontainers/runc@v1.1.14&&\ - go mod tidy && go mod vendor -RUN make GO_REQUIRED_MIN_VERSION:= oc - -FROM fedora:40 -ARG PR_NUMBER -ARG TAG -RUN groupadd -g 1001 krkn && useradd -m -u 1001 -g krkn krkn -RUN dnf update -y - -ENV KUBECONFIG /home/krkn/.kube/config - -# install kubectl -RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" &&\ - cp kubectl /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl &&\ - cp kubectl /usr/bin/kubectl && chmod +x /usr/bin/kubectl - -# This overwrites any existing configuration in /etc/yum.repos.d/kubernetes.repo -RUN dnf update && dnf install -y --setopt=install_weak_deps=False \ - git python39 jq yq gettext wget which &&\ - dnf clean all - -# copy oc client binary from oc-build image -COPY --from=oc-build /tmp/oc/oc /usr/bin/oc - -# krkn build -RUN git clone https://github.com/krkn-chaos/krkn.git /home/krkn/kraken && \ - mkdir -p /home/krkn/.kube - -WORKDIR /home/krkn/kraken - -# default behaviour will be to build main -# if it is a PR trigger the PR itself will be checked out -RUN if [ -n "$PR_NUMBER" ]; then git fetch origin pull/${PR_NUMBER}/head:pr-${PR_NUMBER} && git checkout pr-${PR_NUMBER};fi -# if it is a TAG trigger checkout the tag -RUN if [ -n "$TAG" ]; then git checkout "$TAG";fi - -RUN python3.9 -m ensurepip -RUN pip3.9 install -r requirements.txt -RUN pip3.9 install jsonschema - -LABEL krknctl.title="Krkn Base Image" -LABEL krknctl.description="This is the krkn base image." -LABEL krknctl.input_fields='[ { "name": "cerberus-enabled", "short_description": "Enable Cerberus", "description": "Enables Cerberus Support", "variable": "CERBERUS_ENABLED", "type": "enum", "default": "False", "allowed_values": "True,False", "separator": ",", "required": "false" }, { "name": "cerberus-url", "short_description": "Cerberus URL", "description": "Cerberus http url", "variable": "CERBERUS_URL", "type": "string", "default": "http://0.0.0.0:8080", "validator": "^(http|https):\/\/.*", "required": "false" }, { "name": "distribution", "short_description": "Orchestrator distribution", "description": "Selects the orchestrator distribution", "variable": "DISTRIBUTION", "type": "enum", "default": "openshift", "allowed_values": "openshift,kubernetes", "separator": ",", "required": "false" }, { "name": "krkn-kubeconfig", "short_description": "Krkn kubeconfig path", "description": "Sets the path where krkn will search for kubeconfig (in container)", "variable": "KRKN_KUBE_CONFIG", "type": "string", "default": "/home/krkn/.kube/config", "required": "false" }, { "name": "wait-duration", "short_description": "Post chaos wait duration", "description": "waits for a certain amount of time after the scenario", "variable": "WAIT_DURATION", "type": "number", "default": "1" }, { "name": "iterations", "short_description": "Chaos scenario iterations", "description": "number of times the same chaos scenario will be executed", "variable": "ITERATIONS", "type": "number", "default": "1" }, { "name": "daemon-mode", "short_description": "Sets krkn daemon mode", "description": "if set the scenario will execute forever", "variable": "DAEMON_MODE", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "False", "required": "false" }, { "name": "uuid", "short_description": "Sets krkn run uuid", "description": "sets krkn run uuid instead of generating it", "variable": "UUID", "type": "string", "default": "", "required": "false" }, { "name": "capture-metrics", "short_description": "Enables metrics capture", "description": "Enables metrics capture", "variable": "CAPTURE_METRICS", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "False", "required": "false" }, { "name": "enable-alerts", "short_description": "Enables cluster alerts check", "description": "Enables cluster alerts check", "variable": "ENABLE_ALERTS", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "False", "required": "false" }, { "name": "alerts-path", "short_description": "Cluster alerts path file (in container)", "description": "Enables cluster alerts check", "variable": "ALERTS_PATH", "type": "string", "default": "config/alerts.yaml", "required": "false" }, { "name": "enable-es", "short_description": "Enables elastic search data collection", "description": "Enables elastic search data collection", "variable": "ENABLE_ES", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "False", "required": "false" }, { "name": "es-server", "short_description": "Elasticsearch instance URL", "description": "Elasticsearch instance URL", "variable": "ES_SERVER", "type": "string", "default": "http://0.0.0.0", "validator": "^(http|https):\/\/.*", "required": "false" }, { "name": "es-port", "short_description": "Elasticsearch instance port", "description": "Elasticsearch instance port", "variable": "ES_PORT", "type": "number", "default": "443", "required": "false" }, { "name": "es-username", "short_description": "Elasticsearch instance username", "description": "Elasticsearch instance username", "variable": "ES_USERNAME", "type": "string", "default": "elastic", "required": "false" }, { "name": "es-password", "short_description": "Elasticsearch instance password", "description": "Elasticsearch instance password", "variable": "ES_PASSWORD", "type": "string", "default": "", "required": "false" }, { "name": "es-verify-certs", "short_description": "Enables elasticsearch TLS certificate verification", "description": "Enables elasticsearch TLS certificate verification", "variable": "ES_VERIFY_CERTS", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "False", "required": "false" }, { "name": "es-collect-metrics", "short_description": "Enables metrics collection on elastic search", "description": "Enables metrics collection on elastic search", "variable": "ES_COLLECT_METRICS", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "False", "required": "false" }, { "name": "es-collect-alerts", "short_description": "Enables alerts collection on elastic search", "description": "Enables alerts collection on elastic search", "variable": "ES_COLLECT_ALERTS", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "False", "required": "false" }, { "name": "es-metrics-index", "short_description": "Elasticsearch metrics index", "description": "Index name for metrics in Elasticsearch", "variable": "ES_METRICS_INDEX", "type": "string", "default": "krkn-metrics", "required": "false" }, { "name": "es-alerts-index", "short_description": "Elasticsearch alerts index", "description": "Index name for alerts in Elasticsearch", "variable": "ES_ALERTS_INDEX", "type": "string", "default": "krkn-alerts", "required": "false" }, { "name": "es-telemetry-index", "short_description": "Elasticsearch telemetry index", "description": "Index name for telemetry in Elasticsearch", "variable": "ES_TELEMETRY_INDEX", "type": "string", "default": "krkn-telemetry", "required": "false" }, { "name": "check-critical-alerts", "short_description": "Check critical alerts", "description": "Enables checking for critical alerts", "variable": "CHECK_CRITICAL_ALERTS", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "False", "required": "false" }, { "name": "telemetry-enabled", "short_description": "Enable telemetry", "description": "Enables telemetry support", "variable": "TELEMETRY_ENABLED", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "False", "required": "false" }, { "name": "telemetry-api-url", "short_description": "Telemetry API URL", "description": "API endpoint for telemetry data", "variable": "TELEMETRY_API_URL", "type": "string", "default": "https://ulnmf9xv7j.execute-api.us-west-2.amazonaws.com/production", "validator": "^(http|https):\/\/.*", "required": "false" }, { "name": "telemetry-username", "short_description": "Telemetry username", "description": "Username for telemetry authentication", "variable": "TELEMETRY_USERNAME", "type": "string", "default": "redhat-chaos", "required": "false" }, { "name": "telemetry-password", "short_description": "Telemetry password", "description": "Password for telemetry authentication", "variable": "TELEMETRY_PASSWORD", "type": "string", "default": "", "required": "false" }, { "name": "telemetry-prometheus-backup", "short_description": "Prometheus backup for telemetry", "description": "Enables Prometheus backup for telemetry", "variable": "TELEMETRY_PROMETHEUS_BACKUP", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "True", "required": "false" }, { "name": "telemetry-full-prometheus-backup", "short_description": "Full Prometheus backup", "description": "Enables full Prometheus backup for telemetry", "variable": "TELEMETRY_FULL_PROMETHEUS_BACKUP", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "False", "required": "false" }, { "name": "telemetry-backup-threads", "short_description": "Telemetry backup threads", "description": "Number of threads for telemetry backup", "variable": "TELEMETRY_BACKUP_THREADS", "type": "number", "default": "5", "required": "false" }, { "name": "telemetry-archive-path", "short_description": "Telemetry archive path", "description": "Path to save telemetry archive", "variable": "TELEMETRY_ARCHIVE_PATH", "type": "string", "default": "/tmp", "required": "false" }, { "name": "telemetry-max-retries", "short_description": "Telemetry max retries", "description": "Maximum retries for telemetry operations", "variable": "TELEMETRY_MAX_RETRIES", "type": "number", "default": "0", "required": "false" }, { "name": "telemetry-run-tag", "short_description": "Telemetry run tag", "description": "Tag for telemetry run", "variable": "TELEMETRY_RUN_TAG", "type": "string", "default": "chaos", "required": "false" }, { "name": "telemetry-group", "short_description": "Telemetry group", "description": "Group name for telemetry data", "variable": "TELEMETRY_GROUP", "type": "string", "default": "default", "required": "false" }, { "name": "telemetry-archive-size", "short_description": "Telemetry archive size", "description": "Maximum size for telemetry archives", "variable": "TELEMETRY_ARCHIVE_SIZE", "type": "number", "default": "1000", "required": "false" }, { "name": "telemetry-logs-backup", "short_description": "Telemetry logs backup", "description": "Enables logs backup for telemetry", "variable": "TELEMETRY_LOGS_BACKUP", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "False", "required": "false" }, { "name": "telemetry-filter-pattern", "short_description": "Telemetry filter pattern", "description": "Filter pattern for telemetry logs", "variable": "TELEMETRY_FILTER_PATTERN", "type": "string", "default": "[\"(\\\\w{3}\\\\s\\\\d{1,2}\\\\s\\\\d{2}:\\\\d{2}:\\\\d{2}\\\\.\\\\d+).+\",\"kinit (\\\\d+/\\\\d+/\\\\d+\\\\s\\\\d{2}:\\\\d{2}:\\\\d{2})\\\\s+\",\"(\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}\\\\.\\\\d+Z).+\"]", "required": "false" }, { "name": "telemetry-cli-path", "short_description": "Telemetry CLI path (oc)", "description": "Path to telemetry CLI tool (oc)", "variable": "TELEMETRY_CLI_PATH", "type": "string", "default": "", "required": "false" }, { "name": "telemetry-events-backup", "short_description": "Telemetry events backup", "description": "Enables events backup for telemetry", "variable": "TELEMETRY_EVENTS_BACKUP", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "True", "required": "false" }, { "name": "krkn-debug", "short_description": "Krkn debug mode", "description": "Enables debug mode for Krkn", "variable": "KRKN_DEBUG", "type": "enum", "allowed_values": "True,False", "separator": ",", "default": "False", "required": "false" }]' - - -RUN chown -R krkn:krkn /home/krkn && chmod 755 /home/krkn -USER krkn -ENTRYPOINT ["python3.9", "run_kraken.py"] -CMD ["--config=config/config.yaml"] diff --git a/containers/build.sh b/containers/compile_dockerfile.sh similarity index 60% rename from containers/build.sh rename to containers/compile_dockerfile.sh index 889c1cce..3f531eb7 100755 --- a/containers/build.sh +++ b/containers/compile_dockerfile.sh @@ -1,2 +1,5 @@ +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" export KRKNCTL_INPUT=$(cat krknctl-input.json|tr -d "\n") + envsubst '${KRKNCTL_INPUT}' < Dockerfile.template > Dockerfile \ No newline at end of file