version: 0.2      

env:
  variables:
    CONTAINER_VARIABLES: "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI EKS_PRIVATE_SUBNETS EKS_PUBLIC_SUBNETS PYTEST_MARKER PYTEST_ADDOPTS S3_DATA_BUCKET EKS_EXISTING_CLUSTER SAGEMAKER_EXECUTION_ROLE_ARN REGION SKIP_FSX_TESTS ROBOMAKER_EXECUTION_ROLE_ARN"

phases:
  pre_build:
    commands:
      - aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $ECR_CACHE_URI || true
      - docker pull ${ECR_CACHE_URI}:latest --quiet || true
      # Build test image
      - >
        docker build -f ./components/aws/sagemaker/tests/integration_tests/Dockerfile . -t ${ECR_CACHE_URI}:latest --quiet
        || echo "Docker Build Failed" || true
  build:
    commands:
      # Run the container and copy the results to /tmp
      # Passes all listed host environment variables through to the container
      - docker run --name integration-test-container $(env | cut -f1 -d= | sed 's/^/-e /') --mount type=bind,source="$(pwd)/",target="/pipelines/" ${ECR_CACHE_URI}:latest

  post_build:
    commands:
      - docker cp integration-test-container:/pipelines/components/aws/sagemaker/tests/integration_tests/integration_tests.xml /tmp/results.xml || true
      # Push test image to cache ECR repo
      - docker push ${ECR_CACHE_URI}:latest || true

reports:
  IntegrationTestReport:
    files:
      - "results.xml"
    base-directory: "/tmp"
