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
- 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:

View File

@ -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}

View File

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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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)

View File

@ -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()

View File

@ -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