Use immutable tags for running tasks

This way we can run tasks with `IfNotPresent` and be sure it works as intended.
This commit is contained in:
Mehran Kholdi 2020-05-29 19:20:03 +04:30
parent 0ab1e393fc
commit 46bd3565a0
9 changed files with 33 additions and 8 deletions

View File

@ -7,7 +7,13 @@ build:
- export REGISTRY=docker.io - export REGISTRY=docker.io
- mkdir -p ~/.docker/; echo $DOCKER_AUTH_CONFIG >~/.docker/config.json - mkdir -p ~/.docker/; echo $DOCKER_AUTH_CONFIG >~/.docker/config.json
- export IMAGE="$REGISTRY/$IMAGE_REPO" - 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_SHORT_SHA
- docker push $IMAGE:$CI_COMMIT_REF_SLUG - docker push $IMAGE:$CI_COMMIT_REF_SLUG
tags: tags:

View File

@ -1,3 +1,5 @@
ARG IMAGE_TAG
ARG IMAGE_REPOSITORY
FROM python:3 FROM python:3
WORKDIR /app/ WORKDIR /app/
@ -11,3 +13,9 @@ ADD ./ ./
ENTRYPOINT ["/usr/bin/env", "python3", "/app/rawfile.py"] ENTRYPOINT ["/usr/bin/env", "python3", "/app/rawfile.py"]
CMD ["csi-driver"] CMD ["csi-driver"]
ENV PYTHONUNBUFFERED 1 ENV PYTHONUNBUFFERED 1
ARG IMAGE_TAG
ARG IMAGE_REPOSITORY
ENV IMAGE_REPOSITORY ${IMAGE_REPOSITORY}
ENV IMAGE_TAG ${IMAGE_TAG}

View File

@ -1 +1,2 @@
DATA_DIR = "/data" DATA_DIR = "/data"
CONFIG = {}

View File

@ -2,5 +2,5 @@ apiVersion: v2
name: rawfile-csi name: rawfile-csi
description: RawFile Driver Container Storage Interface description: RawFile Driver Container Storage Interface
type: application type: application
version: 0.1.1 version: 0.1.2
appVersion: 0.0.1 appVersion: 0.0.1

View File

@ -44,6 +44,8 @@ spec:
env: env:
- name: CSI_ENDPOINT - name: CSI_ENDPOINT
value: unix:///csi/csi.sock value: unix:///csi/csi.sock
- name: IMAGE_REPOSITORY
value: "{{ .Values.controller.image.repository }}"
volumeMounts: volumeMounts:
- name: socket-dir - name: socket-dir
mountPath: /csi mountPath: /csi

View File

@ -62,6 +62,8 @@ spec:
env: env:
- name: CSI_ENDPOINT - name: CSI_ENDPOINT
value: unix:///csi/csi.sock value: unix:///csi/csi.sock
- name: IMAGE_REPOSITORY
value: "{{ .Values.node.image.repository }}"
- name: NODE_ID - name: NODE_ID
valueFrom: valueFrom:
fieldRef: fieldRef:

View File

@ -7,6 +7,8 @@ import pykube
import yaml import yaml
from munch import Munch from munch import Munch
from consts import CONFIG
api = pykube.HTTPClient(pykube.KubeConfig.from_env()) api = pykube.HTTPClient(pykube.KubeConfig.from_env())
@ -46,6 +48,8 @@ def run_on_node(fn, node):
"namespace": "kube-system", # FIXME "namespace": "kube-system", # FIXME
"nodeSelector": json.dumps({"kubernetes.io/hostname": node}), "nodeSelector": json.dumps({"kubernetes.io/hostname": node}),
"cmd": json.dumps(fn), "cmd": json.dumps(fn),
"image_repository": CONFIG["image_repository"],
"image_tag": CONFIG["image_tag"],
} }
template = Path("./templates/task.yaml").read_bytes().decode() template = Path("./templates/task.yaml").read_bytes().decode()
manifest = template.format(**ctx) manifest = template.format(**ctx)

View File

@ -6,13 +6,17 @@ import click
import grpc import grpc
import rawfile_servicer import rawfile_servicer
from consts import CONFIG
from csi import csi_pb2_grpc from csi import csi_pb2_grpc
from metrics import expose_metrics from metrics import expose_metrics
@click.group() @click.group()
def cli(): @click.option("--image-repository", envvar="IMAGE_REPOSITORY")
pass @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() @cli.command()

View File

@ -16,10 +16,8 @@ spec:
nodeSelector: {nodeSelector} nodeSelector: {nodeSelector}
containers: containers:
- name: task - name: task
# FIXME: use immutable tag image: {image_repository}:{image_tag}
image: docker.io/hamravesh/rawfile-csi:master imagePullPolicy: IfNotPresent
# FIXME: change to IfNotPresent
imagePullPolicy: Always
volumeMounts: volumeMounts:
- name: data-dir - name: data-dir
mountPath: /data mountPath: /data