diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cbfdc62..1b51645 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,7 +7,13 @@ build: - export REGISTRY=docker.io - mkdir -p ~/.docker/; echo $DOCKER_AUTH_CONFIG >~/.docker/config.json - export IMAGE="$REGISTRY/$IMAGE_REPO" - - docker build -t $IMAGE:$CI_COMMIT_SHORT_SHA -t $IMAGE:$CI_COMMIT_REF_SLUG . + - | + docker build \ + -t $IMAGE:$CI_COMMIT_SHORT_SHA \ + -t $IMAGE:$CI_COMMIT_REF_SLUG \ + --build-arg IMAGE_TAG=$CI_COMMIT_SHORT_SHA \ + --build-arg IMAGE_REPOSITORY=$IMAGE \ + . - docker push $IMAGE:$CI_COMMIT_SHORT_SHA - docker push $IMAGE:$CI_COMMIT_REF_SLUG tags: diff --git a/Dockerfile b/Dockerfile index 4e3f34b..bef4c6a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ +ARG IMAGE_TAG +ARG IMAGE_REPOSITORY FROM python:3 WORKDIR /app/ @@ -11,3 +13,9 @@ ADD ./ ./ ENTRYPOINT ["/usr/bin/env", "python3", "/app/rawfile.py"] CMD ["csi-driver"] ENV PYTHONUNBUFFERED 1 + + +ARG IMAGE_TAG +ARG IMAGE_REPOSITORY +ENV IMAGE_REPOSITORY ${IMAGE_REPOSITORY} +ENV IMAGE_TAG ${IMAGE_TAG} diff --git a/consts.py b/consts.py index d5978e3..4077b1b 100644 --- a/consts.py +++ b/consts.py @@ -1 +1,2 @@ DATA_DIR = "/data" +CONFIG = {} diff --git a/deploy/charts/rawfile-csi/Chart.yaml b/deploy/charts/rawfile-csi/Chart.yaml index ac7775c..e9cc096 100644 --- a/deploy/charts/rawfile-csi/Chart.yaml +++ b/deploy/charts/rawfile-csi/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: rawfile-csi description: RawFile Driver Container Storage Interface type: application -version: 0.1.1 +version: 0.1.2 appVersion: 0.0.1 diff --git a/deploy/charts/rawfile-csi/templates/01-controller-plugin.yaml b/deploy/charts/rawfile-csi/templates/01-controller-plugin.yaml index d3be0c0..d4cd428 100644 --- a/deploy/charts/rawfile-csi/templates/01-controller-plugin.yaml +++ b/deploy/charts/rawfile-csi/templates/01-controller-plugin.yaml @@ -44,6 +44,8 @@ spec: env: - name: CSI_ENDPOINT value: unix:///csi/csi.sock + - name: IMAGE_REPOSITORY + value: "{{ .Values.controller.image.repository }}" volumeMounts: - name: socket-dir mountPath: /csi diff --git a/deploy/charts/rawfile-csi/templates/01-node-plugin.yaml b/deploy/charts/rawfile-csi/templates/01-node-plugin.yaml index 2356707..0159d88 100644 --- a/deploy/charts/rawfile-csi/templates/01-node-plugin.yaml +++ b/deploy/charts/rawfile-csi/templates/01-node-plugin.yaml @@ -62,6 +62,8 @@ spec: env: - name: CSI_ENDPOINT value: unix:///csi/csi.sock + - name: IMAGE_REPOSITORY + value: "{{ .Values.node.image.repository }}" - name: NODE_ID valueFrom: fieldRef: diff --git a/orchestrator/k8s.py b/orchestrator/k8s.py index 4906106..13c3e88 100644 --- a/orchestrator/k8s.py +++ b/orchestrator/k8s.py @@ -7,6 +7,8 @@ import pykube import yaml from munch import Munch +from consts import CONFIG + api = pykube.HTTPClient(pykube.KubeConfig.from_env()) @@ -46,6 +48,8 @@ def run_on_node(fn, node): "namespace": "kube-system", # FIXME "nodeSelector": json.dumps({"kubernetes.io/hostname": node}), "cmd": json.dumps(fn), + "image_repository": CONFIG["image_repository"], + "image_tag": CONFIG["image_tag"], } template = Path("./templates/task.yaml").read_bytes().decode() manifest = template.format(**ctx) diff --git a/rawfile.py b/rawfile.py index 647a9d0..86ae230 100755 --- a/rawfile.py +++ b/rawfile.py @@ -6,13 +6,17 @@ import click import grpc import rawfile_servicer +from consts import CONFIG from csi import csi_pb2_grpc from metrics import expose_metrics @click.group() -def cli(): - pass +@click.option("--image-repository", envvar="IMAGE_REPOSITORY") +@click.option("--image-tag", envvar="IMAGE_TAG") +def cli(image_repository, image_tag): + CONFIG["image_repository"] = image_repository + CONFIG["image_tag"] = image_tag @cli.command() diff --git a/templates/task.yaml b/templates/task.yaml index f6b5b27..93b7206 100644 --- a/templates/task.yaml +++ b/templates/task.yaml @@ -16,10 +16,8 @@ spec: nodeSelector: {nodeSelector} containers: - name: task - # FIXME: use immutable tag - image: docker.io/hamravesh/rawfile-csi:master - # FIXME: change to IfNotPresent - imagePullPolicy: Always + image: {image_repository}:{image_tag} + imagePullPolicy: IfNotPresent volumeMounts: - name: data-dir mountPath: /data