Last active
June 28, 2017 20:41
-
-
Save sdr01810/e9f78b9ad5497e8881b5d1288a46aa7b to your computer and use it in GitHub Desktop.
Spin up a JFrog Artifactory server as a Docker container.
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
#!/bin/bash | |
## Spin up a JFrog Artifactory server as a Docker container. | |
## By Stephen D. Rogers <inbox.c7r@steve-rogers.com>, 2017-04. | |
## | |
## Usage: | |
## | |
## artifactory.spin-up [--interactive|-i] [--restart policy] [--tty|-t] [listening_port] | |
## | |
## The Artifactory listening port (on the container host) defaults to 8001. | |
## | |
umask 0002 | |
set -e -o pipefail | |
no_worries() { | |
echo 1>&2 "No worries; continuing." | |
} | |
qq() { | |
printf "%q" "$@" | |
} | |
xx() { | |
echo 1>&2 "+" "$@" | |
"$@" | |
} | |
## | |
run_options= | |
while [ $# -gt 0 ] ; do | |
case "$1" in | |
--interactive|-i) | |
run_options+="${run_options:+ }${1}" | |
shift 1 ; continue | |
;; | |
--restart) | |
run_options+="${run_options:+ }${1} $(qq "${2}")" | |
shift 2 ; continue | |
;; | |
--tty|-t) | |
run_options+="${run_options:+ }${1}" | |
shift 1 ; continue | |
;; | |
--) | |
shift 1 ; break | |
;; | |
-*) | |
echo 1>&2 "unrecognized option: ${1}" | |
exit 2 | |
;; | |
*) | |
break; | |
;; | |
esac | |
done | |
container_name=artifactory | |
container_image=docker.bintray.io/jfrog/artifactory-oss:latest | |
p1h="${1:-8001}" # artifactory listening port on the host | |
p1c="8081" # artifactory listening port in the container | |
for d1h in /var/local/workspaces/artifactory ; do # artifactory data directory on the host | |
for d1c in /var/opt/jfrog/artifactory ; do # artifactory data directory in the container | |
for dxh in "$d1h" ; do | |
# The container determines owner uid/gid for "$dxh" and below; | |
# seal off access to that subtree to just the superuser (root). | |
for dxh_parent in "$(dirname "$(dirname "$dxh")")" ; do | |
xx sudo mkdir -p "$dxh_parent" | |
xx sudo chown root:root "$dxh_parent" | |
xx sudo chmod 0770 "$dxh_parent" | |
xx sudo chmod g+s "$dxh_parent" | |
done;done | |
xx : | |
xx docker pull "$container_image" | |
xx : | |
xx docker stop "$container_name" || no_worries | |
xx docker rm --force "$container_name" || no_worries | |
xx : | |
xx eval "docker run --name $(qq "$container_name") -d \ | |
-v $(qq "$d1h":"$d1c") -p $(qq "$p1h":"$p1c") ${run_options} $(qq "$container_image")" | |
done;done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment