Skip to content

Commit

Permalink
Fixes6
Browse files Browse the repository at this point in the history
  • Loading branch information
iperetz-goo committed Jan 26, 2023
1 parent c404963 commit 8544dac
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions scripts/make-in-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
# run-in-container runs a make command within a
# container. The only required dependency is
# podman or docker: containers required for runtime
# will be pulled or built during the exectuion of the script.
set -e

BUILDER_IMAGE="gcr.io/graphite-docker-images/downstream-builder:latest"
DEV_IMAGE="gcr.io/graphite-docker-images/magic-modules-dev:latest"

main() {
if which podman > /dev/null; then
CONTAINER_EXECUTABLE="podman"
elif which docker > /dev/null; then
CONTAINER_EXECUTABLE="docker"
else
echo "Unable to find podman or docker executable. Please install podman or docker and try again." && exit 1;
fi

echo "Found ${CONTAINER_EXECUTABLE}, using it to run commands."

if ! ${CONTAINER_EXECUTABLE} images | grep "gcr.io/graphite-docker-images/magic-modules-dev" > /dev/null; then
echo "unable to find magic-modules-dev container"
build_dev_container
fi

${CONTAINER_EXECUTABLE} run --rm \
-v "$PWD:/magic-modules" -v "$GOPATH:$GOPATH" \
-it "${DEV_IMAGE}" "$@"
}


build_dev_container() {
echo "building containers...."
echo "NOTE: this may take a while."
sleep 1
if ! ${CONTAINER_EXECUTABLE} images | grep "${BUILDER_IMAGE}" > /dev/null; then
if ! ${CONTAINER_EXECUTABLE} pull "${BUILDER_IMAGE}"; then
${CONTAINER_EXECUTABLE} build \
.ci/containers/downstream-builder/ \
-t "${BUILDER_IMAGE}"
fi
fi
${CONTAINER_EXECUTABLE} build \
.ci/containers/magic-modules-dev/ \
-t "${DEV_IMAGE}"
}

main "$@"

0 comments on commit 8544dac

Please sign in to comment.