-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c404963
commit 8544dac
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "$@" |