diff --git a/.github/workflows/gh-build.yml b/.github/workflows/gh-build.yml index fcf577b3d..c574b2f66 100644 --- a/.github/workflows/gh-build.yml +++ b/.github/workflows/gh-build.yml @@ -54,35 +54,42 @@ jobs: echo BUILD_TARGET: ${{ inputs.build-target }} echo USE_CUDA: ${{ env.USE_CUDA }} + IMAGE_TAG=${{ env.IMAGE_NAME }}:${{ inputs.sha }} + chmod +x continuous_integration/build-docker-image continuous_integration/build-docker-image \ --base-image "$BASE_IMAGE" \ - --image-name "$IMAGE_NAME" \ - --sha ${{ inputs.sha }} \ + --image-tag "$IMAGE_TAG" \ --source-dir . + - name: Dump docker history of image before upload + run: | + IMAGE_TAG=${{ env.IMAGE_NAME }}:${{ inputs.sha }} + docker history $IMAGE_TAG + - name: Log in to container image registry run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin - name: Push image run: | - IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + IMAGE_TAG=${{ env.IMAGE_NAME }}:${{ inputs.sha }} + + IMAGE_ID=ghcr.io/${{ github.repository_owner }} # Change all uppercase to lowercase IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - VERSION=${{ inputs.sha }} + IMAGE_ID=$IMAGE_ID/$IMAGE_TAG - docker tag $IMAGE_NAME:$VERSION $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION + docker tag $IMAGE_TAG $IMAGE_ID + docker push $IMAGE_ID - name: Copy artifacts back to the host run: | + IMAGE_TAG=${{ env.IMAGE_NAME }}:${{ inputs.sha }} mkdir -p artifacts - docker run -v "$(pwd)/artifacts:/home/coder/.artifacts" --rm -t $IMAGE_NAME:${{ inputs.sha }} copy-artifacts - echo --------- DOCKER HISTORY START ----------- - docker history $IMAGE_NAME:${{ inputs.sha }} - echo --------- DOCKER HISTORY END ----------- + docker run -v "$(pwd)/artifacts:/home/coder/.artifacts" --rm -t $IMAGE_TAG copy-artifacts + - name: Display structure of workdir run: ls -R diff --git a/continuous_integration/build-docker-image b/continuous_integration/build-docker-image index 6c46ff839..e36cf7974 100755 --- a/continuous_integration/build-docker-image +++ b/continuous_integration/build-docker-image @@ -3,8 +3,8 @@ set -xuo pipefail #Set the options of the getopt command -format=$(getopt -n "$0" -l "base-image:,image-name:,sha:,source-dir:" -- -- "$@") -if [ $# -lt 5 ]; then +format=$(getopt -n "$0" -l "base-image:,image-tag:,source-dir:" -- -- "$@") +if [ $# -lt 4 ]; then echo "Wrong number of arguments passed." exit fi @@ -15,8 +15,7 @@ while [ $# -gt 0 ] do case "$1" in --base-image) BASE_IMAGE="$2"; shift;; - --image-name) IMAGE_NAME="$2"; shift;; - --sha) SHA="$2"; shift;; + --image-tag) IMAGE_TAG="$2"; shift;; --source-dir) SOURCE_DIR="$2"; shift;; --) shift;; esac @@ -26,16 +25,15 @@ done set -e # Avoid build errors due to a missing .creds folder -mkdir -p $SOURCE_DIR/.creds +mkdir -p "$SOURCE_DIR/.creds" docker build \ - --build-arg BASE_IMAGE=$BASE_IMAGE \ - --build-arg AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \ - --build-arg AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ - --build-arg AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ - --build-arg GITHUB_TOKEN=$GITHUB_TOKEN \ - --build-arg USE_CUDA=$USE_CUDA \ + --build-arg BASE_IMAGE="$BASE_IMAGE" \ + --build-arg AWS_SESSION_TOKEN="$AWS_SESSION_TOKEN" \ + --build-arg AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" \ + --build-arg AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" \ + --build-arg GITHUB_TOKEN="$GITHUB_TOKEN" \ + --build-arg USE_CUDA="$USE_CUDA" \ --progress=plain \ - --tag=$IMAGE_NAME:$SHA \ - --label "git-commit=$SHA" \ - -f $SOURCE_DIR/continuous_integration/Dockerfile $SOURCE_DIR + --tag="$IMAGE_TAG" \ + -f "$SOURCE_DIR/continuous_integration/Dockerfile" "$SOURCE_DIR"