diff --git a/components/aws/sagemaker/codebuild/deploy.buildspec.yml b/components/aws/sagemaker/codebuild/deploy.buildspec.yml new file mode 100644 index 00000000000..f2acff30a45 --- /dev/null +++ b/components/aws/sagemaker/codebuild/deploy.buildspec.yml @@ -0,0 +1,12 @@ +version: 0.2 +phases: + pre_build: + commands: + # Log in to Dockerhub + - mkdir -p ~/.docker + - echo $DOCKER_CONFIG > ~/.docker/config.json + + build: + commands: + - cd components/aws/sagemaker + - ./codebuild/scripts/deploy.sh -d "${DRY_RUN}" \ No newline at end of file diff --git a/components/aws/sagemaker/codebuild/integration-test.buildspec.yml b/components/aws/sagemaker/codebuild/integration-test.buildspec.yml new file mode 100644 index 00000000000..0ca12b06c61 --- /dev/null +++ b/components/aws/sagemaker/codebuild/integration-test.buildspec.yml @@ -0,0 +1,18 @@ +version: 0.2 +phases: + build: + commands: + - cd components/aws + - docker build . -f ./sagemaker/tests/integration_tests/Dockerfile -t amazon/integration-test-image --quiet + + # Run the container and copy the results to /tmp + # Passes all host environment variables through to the container + - docker run --name integration-test-container $(env | cut -f1 -d= | sed 's/^/-e /') amazon/integration-test-image + - docker cp integration-test-container:/app/tests/integration_tests/integration_tests.log /tmp/results.xml + - docker rm -f integration-test-container + +reports: + IntegrationTestReport: + files: + - "results.xml" + base-directory: "/tmp" \ No newline at end of file diff --git a/components/aws/sagemaker/codebuild/scripts/deploy.sh b/components/aws/sagemaker/codebuild/scripts/deploy.sh new file mode 100755 index 00000000000..aa023f00512 --- /dev/null +++ b/components/aws/sagemaker/codebuild/scripts/deploy.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash + +set -e + +REMOTE_REPOSITORY="amazon/aws-sagemaker-kfp-components" +DRYRUN="true" +FULL_VERSION_TAG="" + +while getopts ":d:v:" opt; do + case ${opt} in + d) + if [[ "${OPTARG}" = "false" ]]; then + DRYRUN="false" + else + DRYRUN="true" + fi + ;; + v) + FULL_VERSION_TAG="${OPTARG}" + ;; + esac +done + +function docker_tag_exists() { + curl --silent -f -lSL https://index.docker.io/v1/repositories/$1/tags/$2 > /dev/null 2> /dev/null +} + +if [[ ! -z "${FULL_VERSION_TAG}" && ! "${FULL_VERSION_TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then + >&2 echo "Version tag does not match SEMVER style (X.Y.Z)" + exit 1 +fi + +# Check version does not already exist +VERSION_LICENSE_FILE="THIRD-PARTY-LICENSES.txt" +if [[ -z "${FULL_VERSION_TAG}" ]]; then + FULL_VERSION_TAG="$(cat ${VERSION_LICENSE_FILE} | head -n1 | grep -Po '(?<=version )\d.\d.\d')" +fi + +if [ -z "$FULL_VERSION_TAG" ]; then + >&2 echo "Could not find version inside ${VERSION_LICENSE_FILE} file." + exit 1 +fi + +echo "Deploying version ${FULL_VERSION_TAG}" + +if docker_tag_exists "$REMOTE_REPOSITORY" "$FULL_VERSION_TAG"; then + >&2 echo "Tag ${REMOTE_REPOSITORY}:${FULL_VERSION_TAG} already exists. Cannot overwrite an existing image." + exit 1 +fi + +# Build the image +FULL_VERSION_IMAGE="${REMOTE_REPOSITORY}:${FULL_VERSION_TAG}" +docker build . -f Dockerfile -t "${FULL_VERSION_IMAGE}" + +# Get the minor and major versions +[[ $FULL_VERSION_TAG =~ ^[0-9]+\.[0-9]+ ]] && MINOR_VERSION_IMAGE="${REMOTE_REPOSITORY}:${BASH_REMATCH[0]}" +[[ $FULL_VERSION_TAG =~ ^[0-9]+ ]] && MAJOR_VERSION_IMAGE="${REMOTE_REPOSITORY}:${BASH_REMATCH[0]}" + +# Re-tag the image with major and minor versions +docker tag "${FULL_VERSION_IMAGE}" "${MINOR_VERSION_IMAGE}" +echo "Tagged image with ${MINOR_VERSION_IMAGE}" +docker tag "${FULL_VERSION_IMAGE}" "${MAJOR_VERSION_IMAGE}" +echo "Tagged image with ${MAJOR_VERSION_IMAGE}" + +# Push to the remote repository +if [ "${DRYRUN}" == "false" ]; then + docker push "${FULL_VERSION_IMAGE}" + echo "Successfully pushed tag ${FULL_VERSION_IMAGE} to Docker Hub" + + docker push "${MINOR_VERSION_IMAGE}" + echo "Successfully pushed tag ${MINOR_VERSION_IMAGE} to Docker Hub" + + docker push "${MAJOR_VERSION_IMAGE}" + echo "Successfully pushed tag ${MAJOR_VERSION_IMAGE} to Docker Hub" +else + echo "Dry run detected. Not pushing images." +fi \ No newline at end of file diff --git a/components/aws/sagemaker/codebuild/unit-test.buildspec.yml b/components/aws/sagemaker/codebuild/unit-test.buildspec.yml new file mode 100644 index 00000000000..a366094bfa4 --- /dev/null +++ b/components/aws/sagemaker/codebuild/unit-test.buildspec.yml @@ -0,0 +1,18 @@ +version: 0.2 +phases: + build: + commands: + - cd components/aws + - docker build . -f ./sagemaker/tests/unit_tests/Dockerfile -t amazon/unit-test-image --quiet + + # Run the container and copy the results to /tmp + # Passes all host environment variables through to the container + - docker run --name unit-test-container $(env | cut -f1 -d= | sed 's/^/-e /') amazon/unit-test-image + - docker cp unit-test-container:/app/tests/unit_tests/unit_tests.log /tmp/results.xml + - docker rm -f unit-test-container + +reports: + UnitTestReport: + files: + - "results.xml" + base-directory: "/tmp" \ No newline at end of file