Skip to content

Commit

Permalink
Merge pull request #43 from viaacode/pkg-version-block-tag
Browse files Browse the repository at this point in the history
Try to add package version as block tag
  • Loading branch information
lennertvandevelde authored Jun 25, 2024
2 parents 91371b6 + 985a1c2 commit 7371e34
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .openshift/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pipeline {
env.IMAGE_TAG = sh(script: 'git describe --tags || echo latest', returnStdout: true)
// The name used for the build config based on the image tag
// Replace '.' with '_' as '.' is not allowed.
env.BUILD_CONFIG_NAME = sh(script: 'echo "${IMAGE_TAG}" | tr -d \'\\n\'', returnStdout: true)
env.BUILD_CONFIG_NAME = sh(script: 'echo "${IMAGE_TAG}" | tr -d \'\\n\' | sed -r "s/\\-//g"', returnStdout: true)
env.DOCKER_IMAGE = sh(script: 'echo "${APP_NAME}:${GIT_SHORT_COMMIT}"')
}
}
Expand Down Expand Up @@ -148,7 +148,7 @@ pipeline {
}
steps {
script {
runInPrefectContainer("python tests/flows/infra_block.py --image $REGISTRY/prefect/prefect-meemoo-test-flows:$GIT_SHORT_COMMIT --name prefect-meemoo-test-flows-$DEPLOYMENT_ENV --registry docker-registry")
runInPrefectContainer("python tests/flows/infra_block.py --image $REGISTRY/prefect/prefect-meemoo-test-flows:$GIT_SHORT_COMMIT --name prefect-meemoo-test-flows-$DEPLOYMENT_ENV --registry docker-registry --package_version ${BUILD_CONFIG_NAME}")
}
}
}
Expand All @@ -160,7 +160,7 @@ pipeline {
script {
def flows = readYaml file: '.openshift/flows.yaml'
for (flow in flows.flows) {
runInPrefectContainer("prefect deployment build tests/flows/${flow.filename}:${flow.function} -n ${flow.name}-$DEPLOYMENT_ENV -ib docker-container/prefect-meemoo-test-flows-$DEPLOYMENT_ENV --skip-upload -q $PREFECT_QUEUE --apply")
runInPrefectContainer("prefect deployment build tests/flows/${flow.filename}:${flow.function} -n ${flow.name}-$DEPLOYMENT_ENV -ib docker-container/prefect-meemoo-test-flows-$DEPLOYMENT_ENV --skip-upload -q $PREFECT_QUEUE -t ${BUILD_CONFIG_NAME} --apply")
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion prefect_meemoo/config/blocks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
from importlib.metadata import version

import pendulum
from dateutil import parser
from prefect.blocks.core import Block, SecretStr
Expand Down Expand Up @@ -28,7 +31,10 @@ class LastRunConfig(Block):
last_run_dict: dict = Field({}, description="Dictionary containing dates based on a certain value for a flow.")
flow_name: str = Field(default=(...), description="The name of the flow.")
name: str = Field(default=(...), description="The name of the deployment.")
_block_schema_capabilities = ["meemoo-prefect", "config"]
try:
_block_schema_capabilities = ["meemoo-prefect", "config", os.environ["BUILD_CONFIG_NAME"]]
except KeyError:
_block_schema_capabilities = ["meemoo-prefect", "config", "v"+ version('prefect-meemoo')]

def get_last_run(self, format: str = "%Y-%m-%dT%H:%M:%S.%fZ", context: str = ""):
if context:
Expand Down
9 changes: 7 additions & 2 deletions prefect_meemoo/elasticsearch/credentials.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
from importlib.metadata import version

import urllib3
from elasticsearch import Elasticsearch
from prefect.blocks.core import Block, SecretStr
Expand Down Expand Up @@ -27,8 +30,10 @@ class ElasticsearchCredentials(Block):
password: SecretStr = Field(default=(...), description="Elasticsearch password.")
username: str = Field(default=(...), description="Elasticsearch username.")
url: str = Field(default=(...), description="Elasticsearch URL.")

_block_schema_capabilities = ["meemoo-prefect", "credentials"]
try:
_block_schema_capabilities = ["meemoo-prefect", "credentials", os.environ["BUILD_CONFIG_NAME"]]
except KeyError:
_block_schema_capabilities = ["meemoo-prefect", "credentials", "v"+ version('prefect-meemoo')]

def get_client(self) -> Elasticsearch:
"""
Expand Down
8 changes: 7 additions & 1 deletion prefect_meemoo/mediahaven/credentials.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
from importlib.metadata import version

from mediahaven import MediaHaven
from mediahaven.oauth2 import ROPCGrant
from prefect.blocks.core import Block, SecretStr
Expand Down Expand Up @@ -34,7 +37,10 @@ class MediahavenCredentials(Block):
username: str = Field(default=(...), description="Mediahaven API username.")
url: str = Field(default=(...), description="Mediahaven API URL.")

_block_schema_capabilities = ["meemoo-prefect", "credentials"]
try:
_block_schema_capabilities = ["meemoo-prefect", "credentials", os.environ["BUILD_CONFIG_NAME"]]
except KeyError:
_block_schema_capabilities = ["meemoo-prefect", "credentials", "v"+ version('prefect-meemoo')]

def get_client(self) -> MediaHaven:
"""
Expand Down
8 changes: 7 additions & 1 deletion prefect_meemoo/triplydb/credentials.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
from importlib.metadata import version

from prefect.blocks.core import Block, SecretStr
from pydantic import Field

Expand Down Expand Up @@ -28,4 +31,7 @@ class TriplyDBCredentials(Block):

host: str = Field(default=(...), description="TriplyDB HTTP host address.")
gitlab_token: SecretStr = Field(default="", description="Gitlab token.")
_block_schema_capabilities = ["meemoo-prefect", "credentials"]
try:
_block_schema_capabilities = ["meemoo-prefect", "credentials", os.environ["BUILD_CONFIG_NAME"]]
except KeyError:
_block_schema_capabilities = ["meemoo-prefect", "credentials", "v"+ version('prefect-meemoo')]
2 changes: 1 addition & 1 deletion tests/flows/flow_test_last_run_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from prefect import flow, get_run_logger, task
from prefect.runtime import deployment, flow_run

from .prefect_meemoo.config.last_run import (add_last_run_with_context,
from prefect_meemoo.config.last_run import (add_last_run_with_context,
get_last_run_config,
save_last_run_config)

Expand Down
12 changes: 10 additions & 2 deletions tests/flows/infra_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
import argparse


def save_image(image_name, name, registry=None) -> None:
def save_image(image_name, name, registry=None, package_version=None) -> None:
docker_registry = DockerRegistry.load(registry)
docker_container = DockerContainer(
image=image_name,
auto_remove=True,
image_registry=docker_registry,
image_pull_policy="ALWAYS",
env={
"BUILD_CONFIG_NAME": package_version
}
)
docker_container.save(name=name, overwrite=True)

Expand All @@ -22,5 +25,10 @@ def save_image(image_name, name, registry=None) -> None:
required=False,
help="Docker registry (the block which it contains), default docker.io",
)
parser.add_argument(
"--package_version",
required=False,
help="The version of the prefect-meemoo package",
)
args = parser.parse_args()
save_image(args.image, args.name, args.registry)
save_image(args.image, args.name, args.registry, args.package_version)

0 comments on commit 7371e34

Please sign in to comment.