diff --git a/.github/jobs/get_met_base_image.sh b/.github/jobs/get_met_base_image.sh new file mode 100755 index 0000000000..1e7efed80c --- /dev/null +++ b/.github/jobs/get_met_base_image.sh @@ -0,0 +1,34 @@ +#! /bin/bash + +# set constants for the MET base repository names (regular and unit test) +MET_BASE_REPO_NAME=met-base +MET_BASE_UNIT_REPO_NAME=met-base-unit-test + +# set MET base repo to regular repo by default for compilation check +met_base_repo=${MET_BASE_REPO_NAME} + +# default MET base tag +met_base_tag=13.0 + +# override the MET base tag if set +if [[ -n "${met_base_tag_override}" ]]; then + met_base_tag=${met_base_tag_override} +fi + +# if running unit tests, use unit_test MET base image +if [[ -n "${RUN_UNIT_TESTS}" && "${RUN_UNIT_TESTS}" == "true" ]]; then + met_base_repo=${MET_BASE_UNIT_REPO_NAME} +fi + +# add -dev to the MET base repo if the tag does not start with a number +# this assumes that met-base and met-base-unit-test tags start with a number and +# development tags, e.g. branch names, do not +if [[ ! ${met_base_tag} =~ ^[0-9] ]]; then + met_base_repo=${met_base_repo}-dev +fi + +echo "met_base_repo=${met_base_repo}" >> $GITHUB_OUTPUT +echo "met_base_tag=${met_base_tag}" >> $GITHUB_OUTPUT + +echo met_base_repo: $met_base_repo +echo met_base_tag: $met_base_tag diff --git a/.github/jobs/set_job_controls.sh b/.github/jobs/set_job_controls.sh index 8a998711db..8d9365f6f7 100755 --- a/.github/jobs/set_job_controls.sh +++ b/.github/jobs/set_job_controls.sh @@ -8,23 +8,6 @@ run_update_truth=false input_data_version=develop truth_data_version=develop -# set constants for the MET base repository names (regular and unit test) -MET_BASE_REPO_NAME=met-base -MET_BASE_UNIT_REPO_NAME=met-base-unit-test - -# set MET base repo to regular repo by default for compilation check -met_base_repo=${MET_BASE_REPO_NAME} - -# default MET base tag -# TODO: Change 3.4 back to 3.5 after solving TC-Diag failure -met_base_tag=3.4-latest - -# override the MET base tag if set -if [[ -n "${met_base_tag_override}" ]]; then - met_base_tag=${met_base_tag_override} -fi - - if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then # only run diff logic if pull request INTO @@ -134,30 +117,18 @@ if [ "$run_update_truth" == "true" ] || fi -# if running unit tests, use unit_test MET base image and push image +# if running unit tests, push the image if [ "$run_unit_tests" == "true" ]; then - # set MET base repo to the unit test version to get the test tools - met_base_repo=${MET_BASE_UNIT_REPO_NAME} - run_push=true fi -# add -dev to the MET base repo if the tag does not start with a number -# this assumes that met-base and met-base-unit-test tags start with a number and -# development tags, e.g. branch names, do not -if [[ ! ${met_base_tag} =~ ^[0-9] ]]; then - met_base_repo=${met_base_repo}-dev -fi - echo "run_compile=${run_compile}" >> $GITHUB_OUTPUT echo "run_push=${run_push}" >> $GITHUB_OUTPUT echo "run_unit_tests=${run_unit_tests}" >> $GITHUB_OUTPUT echo "run_diff=${run_diff}" >> $GITHUB_OUTPUT echo "run_update_truth=${run_update_truth}" >> $GITHUB_OUTPUT -echo "met_base_repo=${met_base_repo}" >> $GITHUB_OUTPUT -echo "met_base_tag=${met_base_tag}" >> $GITHUB_OUTPUT echo "input_data_version=${input_data_version}" >> $GITHUB_OUTPUT echo "truth_data_version=${truth_data_version}" >> $GITHUB_OUTPUT @@ -166,10 +137,12 @@ echo run_push: $run_push echo run_unit_tests: $run_unit_tests echo run_diff: $run_diff echo run_update_truth: $run_update_truth -echo met_base_repo: $met_base_repo -echo met_base_tag: $met_base_tag echo input_data_version: $input_data_version echo truth_data_version: $truth_data_version +# get the METbaseimage repository and tag +export RUN_UNIT_TESTS=${run_unit_tests} +.github/jobs/get_met_base_image.sh + # get name of branch .github/jobs/get_branch_name.sh diff --git a/.github/workflows/build_docker_and_trigger_metplus.yml b/.github/workflows/build_docker_and_trigger_metplus.yml index 4b76478869..f88260f2aa 100644 --- a/.github/workflows/build_docker_and_trigger_metplus.yml +++ b/.github/workflows/build_docker_and_trigger_metplus.yml @@ -31,12 +31,16 @@ jobs: username: ${{ vars.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} + - name: Get METbaseimage + id: get_met_base_image + run: .github/jobs/get_met_base_image.sh + - name: Build Docker Image run: .github/jobs/build_docker_image.sh env: + MET_BASE_REPO: ${{ steps.get_met_base_image.outputs.met_base_repo }} + MET_BASE_TAG: ${{ steps.get_met_base_image.outputs.met_base_tag }} SOURCE_BRANCH: ${{ steps.get_branch_name.outputs.branch_name }}-lite - MET_BASE_REPO: met-base - MET_BASE_TAG: 3.4-latest - name: Push Docker Image run: .github/jobs/push_docker_image.sh diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index 97e013bd85..8cdb407ce7 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -53,6 +53,10 @@ jobs: - name: Create output directories run: mkdir -p ${RUNNER_WORKSPACE}/logs + - name: Get METbaseimage + id: get_met_base_image + run: .github/jobs/get_met_base_image.sh + - name: Get branch name id: get_branch_name run: echo branch_name=${GITHUB_REF#refs/heads/} >> $GITHUB_OUTPUT @@ -60,8 +64,8 @@ jobs: - name: SonarQube Scan in Docker run: .github/jobs/build_sonarqube_image.sh env: - MET_BASE_REPO: met-base - MET_BASE_TAG: 3.4-latest + MET_BASE_REPO: ${{ steps.get_met_base_image.outputs.met_base_repo }} + MET_BASE_TAG: ${{ steps.get_met_base_image.outputs.met_base_tag }} SOURCE_BRANCH: ${{ steps.get_branch_name.outputs.branch_name }} WD_REFERENCE_BRANCH: ${{ github.event.inputs.reference_branch }} SONAR_SCANNER_VERSION: 5.0.1.3006 diff --git a/internal/scripts/docker/Dockerfile b/internal/scripts/docker/Dockerfile index e4572a2ddb..3c792d14b3 100644 --- a/internal/scripts/docker/Dockerfile +++ b/internal/scripts/docker/Dockerfile @@ -1,5 +1,5 @@ ARG MET_BASE_REPO=met-base -ARG MET_BASE_TAG=3.4-latest +ARG MET_BASE_TAG FROM dtcenter/${MET_BASE_REPO}:${MET_BASE_TAG} MAINTAINER John Halley Gotway diff --git a/internal/scripts/docker/Dockerfile.copy b/internal/scripts/docker/Dockerfile.copy index 3d754088d0..104b6441d6 100644 --- a/internal/scripts/docker/Dockerfile.copy +++ b/internal/scripts/docker/Dockerfile.copy @@ -1,5 +1,5 @@ ARG MET_BASE_REPO=met-base-unit-test -ARG MET_BASE_TAG=3.4-latest +ARG MET_BASE_TAG FROM dtcenter/${MET_BASE_REPO}:${MET_BASE_TAG} MAINTAINER John Halley Gotway diff --git a/internal/scripts/docker/Dockerfile.sonarqube b/internal/scripts/docker/Dockerfile.sonarqube index e52b1ae4ba..6c98e46b01 100644 --- a/internal/scripts/docker/Dockerfile.sonarqube +++ b/internal/scripts/docker/Dockerfile.sonarqube @@ -1,5 +1,5 @@ ARG MET_BASE_REPO=met-base -ARG MET_BASE_TAG=3.4-latest +ARG MET_BASE_TAG FROM dtcenter/${MET_BASE_REPO}:${MET_BASE_TAG} MAINTAINER John Halley Gotway diff --git a/internal/scripts/docker/README.md b/internal/scripts/docker/README.md index dae7fa5526..5e733ed144 100644 --- a/internal/scripts/docker/README.md +++ b/internal/scripts/docker/README.md @@ -25,13 +25,14 @@ Tagged versions of the MET Docker image are available in the [dtcenter/met](https://hub.docker.com/repository/docker/dtcenter/met-base) DockerHub repository. ``` -docker build -t dtcenter/met:${TAG_NAME} --build-arg SOURCE_BRANCH=${BRANCH_NAME} internal/scripts/docker +docker build -t dtcenter/met:${TAG_NAME} --build-arg SOURCE_BRANCH=${BRANCH_NAME} --build-arg MET_BASE_TAG=${MET_BASE_TAG} --build-arg internal/scripts/docker docker push dtcenter/met:${TAG_NAME} ``` where: * `${TAG_NAME}` is the name of the DockerHub tag to create * `${BRANCH_NAME}` is the MET branch to checkout +* `${MET_BASE_TAG}` is the version of [dtcenter/met-base-unit-test](https://hub.docker.com/repository/docker/dtcenter/met-base-unit-test) to be used 2. The second example below shows how to manually build a MET Docker image using a specified branch or tag from local source code and using a local @@ -44,26 +45,6 @@ compilation environment.) This example uses `Dockerfile.copy`, which compiles MET using the specified branch or tag from local source code, sets a working directory, and deletes the MET source for tagged releases matching "v"*. ``` -docker build -t dtcenter/met:${TAG_NAME} --build-arg SOURCE_BRANCH=${BRANCH_NAME} -f internal/scripts/docker/Dockerfile.copy . -docker push dtcenter/met:${TAG_NAME} -``` - -where: -* `${TAG_NAME}` is the name of the DockerHub tag to create -* `${BRANCH_NAME}` is the identifier to use for $MET_GIT_NAME inside image - -3. The third example below shows how to manually build a MET Docker image -using a specified branch or tag from local source code and using a local -Docker image for the base compilation environment along with the additional -packages required for running the MET unit tests from the -[METbaseimage](https://github.com/dtcenter/METbaseimage/) -GitHub repository. (See the -[METbaseimage README.md](https://github.com/dtcenter/METbaseimage/blob/main/README.md) -file for more information on manually creating the Docker image with the base -compilation environment and with the additional packages required for running -the MET unit tests.) This example also uses `Dockerfile.copy`, which is -described above. -``` docker build -t dtcenter/met:${TAG_NAME} --build-arg SOURCE_BRANCH=${BRANCH_NAME} --build-arg MET_BASE_TAG=${MET_BASE_TAG} -f internal/scripts/docker/Dockerfile.copy . docker push dtcenter/met:${TAG_NAME} ``` diff --git a/internal/scripts/docker/hooks/build b/internal/scripts/docker/hooks/build deleted file mode 100644 index 5c801c7777..0000000000 --- a/internal/scripts/docker/hooks/build +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -docker build -t $IMAGE_NAME --build-arg SOURCE_BRANCH=$SOURCE_BRANCH .