Skip to content

Commit

Permalink
Removed the --sha arg from build-docker-image.
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepd-nv committed Aug 4, 2023
1 parent 6549c09 commit b70e06c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
27 changes: 17 additions & 10 deletions .github/workflows/gh-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 12 additions & 14 deletions continuous_integration/build-docker-image
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"

0 comments on commit b70e06c

Please sign in to comment.