Skip to content

Commit 09b567f

Browse files
authored
Move docker compose installation scripts from docsite (#878)
* Add cloud provider installation scripts * Add env var for private fork url
1 parent c1ffb7f commit 09b567f

File tree

4 files changed

+273
-0
lines changed

4 files changed

+273
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
###############################################################################
4+
# ACTION REQUIRED: REPLACE THE URL AND REVISION WITH YOUR DEPLOYMENT REPO INFO
5+
###############################################################################
6+
# Please read the notes below the script if you are cloning a private repository
7+
# Example: DEPLOY_SOURCEGRAPH_DOCKER_FORK_REVISION='v4.1.3'
8+
DEPLOY_SOURCEGRAPH_DOCKER_FORK_REVISION="$1"
9+
DEPLOY_SOURCEGRAPH_DOCKER_FORK_CLONE_URL="$2"
10+
##################### NO CHANGES REQUIRED BELOW THIS LINE #####################
11+
if [ "$2" = "" ]; then
12+
DEPLOY_SOURCEGRAPH_DOCKER_FORK_CLONE_URL='https://github.com/sourcegraph/deploy-sourcegraph-docker.git'
13+
fi
14+
DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT='/home/ec2-user/deploy-sourcegraph-docker'
15+
DOCKER_COMPOSE_VERSION='1.29.2'
16+
DOCKER_DAEMON_CONFIG_FILE='/etc/docker/daemon.json'
17+
DOCKER_DATA_ROOT='/mnt/docker-data'
18+
EBS_VOLUME_DEVICE_NAME='/dev/sdb'
19+
EBS_VOLUME_LABEL='sourcegraph'
20+
# Install git
21+
yum update -y
22+
yum install git -y
23+
# Clone the deployment repository
24+
git clone "${DEPLOY_SOURCEGRAPH_DOCKER_FORK_CLONE_URL}" "${DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT}"
25+
cd "${DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT}"
26+
git checkout "${DEPLOY_SOURCEGRAPH_DOCKER_FORK_REVISION}"
27+
# Format (if unformatted) and then mount the attached volume
28+
device_fs=$(lsblk "${EBS_VOLUME_DEVICE_NAME}" --noheadings --output fsType)
29+
if [ "${device_fs}" == "" ]; then
30+
mkfs -t xfs "${EBS_VOLUME_DEVICE_NAME}"
31+
fi
32+
xfs_admin -L "${EBS_VOLUME_LABEL}" "${EBS_VOLUME_DEVICE_NAME}"
33+
mkdir -p "${DOCKER_DATA_ROOT}"
34+
mount -L "${EBS_VOLUME_LABEL}" "${DOCKER_DATA_ROOT}"
35+
# Mount file system by label on reboot
36+
echo "LABEL=${EBS_VOLUME_LABEL} ${DOCKER_DATA_ROOT} xfs defaults,nofail 0 2" >>'/etc/fstab'
37+
umount "${DOCKER_DATA_ROOT}"
38+
mount -a
39+
# Install, configure, and enable Docker
40+
yum update -y
41+
amazon-linux-extras install docker
42+
systemctl enable --now docker
43+
sed -i -e 's/1024/262144/g' /etc/sysconfig/docker
44+
sed -i -e 's/4096/262144/g' /etc/sysconfig/docker
45+
usermod -a -G docker ec2-user
46+
# Install jq for scripting
47+
yum install -y jq
48+
## Initialize the config file with empty json if it doesn't exist
49+
if [ ! -f "${DOCKER_DAEMON_CONFIG_FILE}" ]; then
50+
mkdir -p $(dirname "${DOCKER_DAEMON_CONFIG_FILE}")
51+
echo '{}' >"${DOCKER_DAEMON_CONFIG_FILE}"
52+
fi
53+
## Point Docker storage to mounted volume
54+
tmp_config=$(mktemp)
55+
trap "rm -f ${tmp_config}" EXIT
56+
cat "${DOCKER_DAEMON_CONFIG_FILE}" | jq --arg DATA_ROOT "${DOCKER_DATA_ROOT}" '.["data-root"]=$DATA_ROOT' >"${tmp_config}"
57+
cat "${tmp_config}" >"${DOCKER_DAEMON_CONFIG_FILE}"
58+
# Restart Docker daemon to pick up new changes
59+
systemctl restart --now docker
60+
# Install Docker Compose
61+
curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
62+
chmod +x /usr/local/bin/docker-compose
63+
curl -L "https://raw.githubusercontent.com/docker/compose/${DOCKER_COMPOSE_VERSION}/contrib/completion/bash/docker-compose" -o /etc/bash_completion.d/docker-compose
64+
# Start Sourcegraph with Docker Compose
65+
cd "${DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT}"/docker-compose
66+
docker-compose up -d --remove-orphans
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
###############################################################################
4+
# ACTION REQUIRED: REPLACE THE URL AND REVISION WITH YOUR DEPLOYMENT REPO INFO
5+
###############################################################################
6+
# Please read the notes below the script if you are cloning a private repository
7+
# Example: DEPLOY_SOURCEGRAPH_DOCKER_FORK_REVISION='v4.1.3'
8+
DEPLOY_SOURCEGRAPH_DOCKER_FORK_REVISION="$1"
9+
DEPLOY_SOURCEGRAPH_DOCKER_FORK_CLONE_URL="$2"
10+
##################### NO CHANGES REQUIRED BELOW THIS LINE #####################
11+
if [ "$2" = "" ]; then
12+
DEPLOY_SOURCEGRAPH_DOCKER_FORK_CLONE_URL='https://github.com/sourcegraph/deploy-sourcegraph-docker.git'
13+
fi
14+
DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT='/root/deploy-sourcegraph-docker'
15+
DOCKER_COMPOSE_VERSION='1.29.2'
16+
DOCKER_DAEMON_CONFIG_FILE='/etc/docker/daemon.json'
17+
DOCKER_DATA_ROOT='/mnt/docker-data'
18+
PERSISTENT_DISK_DEVICE_NAME='/dev/sdb'
19+
PERSISTENT_DISK_LABEL='sourcegraph'
20+
# Install git
21+
sudo apt-get update -y
22+
sudo apt-get install -y git
23+
# Clone the deployment repository
24+
git clone "${DEPLOY_SOURCEGRAPH_DOCKER_FORK_CLONE_URL}" "${DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT}"
25+
cd "${DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT}"
26+
git checkout "${DEPLOY_SOURCEGRAPH_DOCKER_FORK_REVISION}"
27+
# Format (if unformatted) and then mount the attached volume
28+
device_fs=$(sudo lsblk "${PERSISTENT_DISK_DEVICE_NAME}" --noheadings --output fsType)
29+
if [ "${device_fs}" == "" ]; then
30+
sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard "${PERSISTENT_DISK_DEVICE_NAME}"
31+
fi
32+
sudo e2label "${PERSISTENT_DISK_DEVICE_NAME}" "${PERSISTENT_DISK_LABEL}"
33+
sudo mkdir -p "${DOCKER_DATA_ROOT}"
34+
sudo mount -o discard,defaults "${PERSISTENT_DISK_DEVICE_NAME}" "${DOCKER_DATA_ROOT}"
35+
# Mount file system by label on reboot
36+
sudo echo "LABEL=${PERSISTENT_DISK_LABEL} ${DOCKER_DATA_ROOT} ext4 discard,defaults,nofail 0 2" | sudo tee -a /etc/fstab
37+
sudo umount "${DOCKER_DATA_ROOT}"
38+
sudo mount -a
39+
# Install, configure, and enable Docker
40+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
41+
sudo apt-get update -y
42+
sudo apt-get install -y software-properties-common
43+
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
44+
sudo apt-get update -y
45+
apt-cache policy docker-ce
46+
apt-get install -y docker-ce docker-ce-cli containerd.io
47+
## Enable Docker at startup
48+
sudo systemctl enable --now docker
49+
## Install jq for scripting
50+
sudo apt-get update -y
51+
sudo apt-get install -y jq
52+
## Initialize the config file with empty json if it doesn't exist
53+
if [ ! -f "${DOCKER_DAEMON_CONFIG_FILE}" ]; then
54+
mkdir -p $(dirname "${DOCKER_DAEMON_CONFIG_FILE}")
55+
echo '{}' >"${DOCKER_DAEMON_CONFIG_FILE}"
56+
fi
57+
## Point Docker storage to mounted volume
58+
tmp_config=$(mktemp)
59+
trap "rm -f ${tmp_config}" EXIT
60+
sudo cat "${DOCKER_DAEMON_CONFIG_FILE}" | sudo jq --arg DATA_ROOT "${DOCKER_DATA_ROOT}" '.["data-root"]=$DATA_ROOT' >"${tmp_config}"
61+
sudo cat "${tmp_config}" >"${DOCKER_DAEMON_CONFIG_FILE}"
62+
## Restart Docker daemon to pick up new changes
63+
sudo systemctl restart --now docker
64+
# Install Docker Compose
65+
curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
66+
chmod +x /usr/local/bin/docker-compose
67+
curl -L "https://raw.githubusercontent.com/docker/compose/${DOCKER_COMPOSE_VERSION}/contrib/completion/bash/docker-compose" -o /etc/bash_completion.d/docker-compose
68+
# Start Sourcegraph with Docker Compose
69+
cd "${DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT}"/docker-compose
70+
docker-compose up -d --remove-orphans
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
###############################################################################
4+
# ACTION REQUIRED: REPLACE THE URL AND REVISION WITH YOUR DEPLOYMENT REPO INFO
5+
###############################################################################
6+
# Please read the notes below the script if you are cloning a private repository
7+
# Example: DEPLOY_SOURCEGRAPH_DOCKER_FORK_REVISION='v4.1.3'
8+
DEPLOY_SOURCEGRAPH_DOCKER_FORK_REVISION="$1"
9+
DEPLOY_SOURCEGRAPH_DOCKER_FORK_CLONE_URL="$2"
10+
##################### NO CHANGES REQUIRED BELOW THIS LINE #####################
11+
if [ "$2" = "" ]; then
12+
DEPLOY_SOURCEGRAPH_DOCKER_FORK_CLONE_URL='https://github.com/sourcegraph/deploy-sourcegraph-docker.git'
13+
fi
14+
DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT='/root/deploy-sourcegraph-docker'
15+
DOCKER_DATA_ROOT='/mnt/docker-data'
16+
DOCKER_COMPOSE_VERSION='1.29.2'
17+
DOCKER_DAEMON_CONFIG_FILE='/etc/docker/daemon.json'
18+
PERSISTENT_DISK_DEVICE_NAME='/dev/sda'
19+
# Install git
20+
sudo apt-get update -y
21+
sudo apt-get install -y git
22+
# Clone the deployment repository
23+
git clone "${DEPLOY_SOURCEGRAPH_DOCKER_FORK_CLONE_URL}" "${DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT}"
24+
cd "${DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT}"
25+
git checkout "${DEPLOY_SOURCEGRAPH_DOCKER_FORK_REVISION}"
26+
# Format (if unformatted) and then mount the attached volume
27+
device_fs=$(sudo lsblk "${PERSISTENT_DISK_DEVICE_NAME}" --noheadings --output fsType)
28+
if [ "${device_fs}" == "" ]; then
29+
sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard "${PERSISTENT_DISK_DEVICE_NAME}"
30+
fi
31+
sudo mkdir -p "${DOCKER_DATA_ROOT}"
32+
sudo mount -o discard,defaults "${PERSISTENT_DISK_DEVICE_NAME}" "${DOCKER_DATA_ROOT}"
33+
# Mount file system by UUID on reboot
34+
DISK_UUID=$(sudo blkid -s UUID -o value "${PERSISTENT_DISK_DEVICE_NAME}")
35+
sudo echo "UUID=${DISK_UUID} ${DOCKER_DATA_ROOT} ext4 discard,defaults,nofail 0 2" >>'/etc/fstab'
36+
sudo umount "${DOCKER_DATA_ROOT}"
37+
sudo mount -a
38+
# Install, configure, and enable Docker
39+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
40+
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
41+
sudo apt-get update -y
42+
apt-cache policy docker-ce
43+
apt-get install -y docker-ce docker-ce-cli containerd.io
44+
## Enable Docker at startup
45+
sudo systemctl enable --now docker
46+
# Install jq for scripting
47+
sudo apt-get update -y
48+
sudo apt-get install -y jq
49+
## Initialize the config file with empty json if it doesn't exist
50+
if [ ! -f "${DOCKER_DAEMON_CONFIG_FILE}" ]; then
51+
mkdir -p $(dirname "${DOCKER_DAEMON_CONFIG_FILE}")
52+
echo '{}' >"${DOCKER_DAEMON_CONFIG_FILE}"
53+
fi
54+
## Point Docker storage to mounted volume
55+
tmp_config=$(mktemp)
56+
trap "rm -f ${tmp_config}" EXIT
57+
sudo cat "${DOCKER_DAEMON_CONFIG_FILE}" | sudo jq --arg DATA_ROOT "${DOCKER_DATA_ROOT}" '.["data-root"]=$DATA_ROOT' >"${tmp_config}"
58+
sudo cat "${tmp_config}" >"${DOCKER_DAEMON_CONFIG_FILE}"
59+
## Restart Docker daemon to pick up new changes
60+
sudo systemctl restart --now docker
61+
# Install Docker Compose
62+
curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
63+
chmod +x /usr/local/bin/docker-compose
64+
curl -L "https://raw.githubusercontent.com/docker/compose/${DOCKER_COMPOSE_VERSION}/contrib/completion/bash/docker-compose" -o /etc/bash_completion.d/docker-compose
65+
# Start Sourcegraph with Docker Compose
66+
cd "${DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT}"/docker-compose
67+
docker-compose up -d --remove-orphans
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
###############################################################################
4+
# ACTION REQUIRED: REPLACE THE URL AND REVISION WITH YOUR DEPLOYMENT REPO INFO
5+
###############################################################################
6+
# Please read the notes below the script if you are cloning a private repository
7+
# Example: DEPLOY_SOURCEGRAPH_DOCKER_FORK_REVISION='v4.1.3'
8+
DEPLOY_SOURCEGRAPH_DOCKER_FORK_REVISION="$1"
9+
DEPLOY_SOURCEGRAPH_DOCKER_FORK_CLONE_URL="$2"
10+
##################### NO CHANGES REQUIRED BELOW THIS LINE #####################
11+
if [ "$2" = "" ]; then
12+
DEPLOY_SOURCEGRAPH_DOCKER_FORK_CLONE_URL='https://github.com/sourcegraph/deploy-sourcegraph-docker.git'
13+
fi
14+
DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT='/root/deploy-sourcegraph-docker'
15+
DOCKER_COMPOSE_VERSION='1.29.2'
16+
DOCKER_DAEMON_CONFIG_FILE='/etc/docker/daemon.json'
17+
DOCKER_DATA_ROOT='/mnt/docker-data'
18+
PERSISTENT_DISK_DEVICE_NAME='/dev/sdb'
19+
PERSISTENT_DISK_LABEL='sourcegraph'
20+
# Install git
21+
sudo apt-get update -y
22+
sudo apt-get install -y git
23+
# Clone the deployment repository
24+
git clone "${DEPLOY_SOURCEGRAPH_DOCKER_FORK_CLONE_URL}" "${DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT}"
25+
cd "${DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT}"
26+
git checkout "${DEPLOY_SOURCEGRAPH_DOCKER_FORK_REVISION}"
27+
# Format (if unformatted) and then mount the attached volume
28+
device_fs=$(sudo lsblk "${PERSISTENT_DISK_DEVICE_NAME}" --noheadings --output fsType)
29+
if [ "${device_fs}" == "" ]; then ## only format the volume if it isn't already formatted
30+
sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard "${PERSISTENT_DISK_DEVICE_NAME}"
31+
fi
32+
sudo e2label "${PERSISTENT_DISK_DEVICE_NAME}" "${PERSISTENT_DISK_LABEL}"
33+
sudo mkdir -p "${DOCKER_DATA_ROOT}"
34+
sudo mount -o discard,defaults "${PERSISTENT_DISK_DEVICE_NAME}" "${DOCKER_DATA_ROOT}"
35+
# Mount file system by label on reboot
36+
sudo echo "LABEL=${PERSISTENT_DISK_LABEL} ${DOCKER_DATA_ROOT} ext4 discard,defaults,nofail 0 2" | sudo tee -a /etc/fstab
37+
sudo umount "${DOCKER_DATA_ROOT}"
38+
sudo mount -a
39+
# Install, configure, and enable Docker
40+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
41+
sudo apt-get update -y
42+
sudo apt-get install -y software-properties-common
43+
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
44+
sudo apt-get update -y
45+
apt-cache policy docker-ce
46+
apt-get install -y docker-ce docker-ce-cli containerd.io
47+
## Enable Docker at startup
48+
sudo systemctl enable --now docker
49+
## Install jq for scripting
50+
sudo apt-get update -y
51+
sudo apt-get install -y jq
52+
## Initialize the config file with empty json if it doesn't exist
53+
if [ ! -f "${DOCKER_DAEMON_CONFIG_FILE}" ]; then
54+
mkdir -p $(dirname "${DOCKER_DAEMON_CONFIG_FILE}")
55+
echo '{}' >"${DOCKER_DAEMON_CONFIG_FILE}"
56+
fi
57+
## Point Docker storage to mounted volume
58+
tmp_config=$(mktemp)
59+
trap "rm -f ${tmp_config}" EXIT
60+
sudo cat "${DOCKER_DAEMON_CONFIG_FILE}" | sudo jq --arg DATA_ROOT "${DOCKER_DATA_ROOT}" '.["data-root"]=$DATA_ROOT' >"${tmp_config}"
61+
sudo cat "${tmp_config}" >"${DOCKER_DAEMON_CONFIG_FILE}"
62+
## Restart Docker daemon to pick up new changes
63+
sudo systemctl restart --now docker
64+
# Install Docker Compose
65+
curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
66+
chmod +x /usr/local/bin/docker-compose
67+
curl -L "https://raw.githubusercontent.com/docker/compose/${DOCKER_COMPOSE_VERSION}/contrib/completion/bash/docker-compose" -o /etc/bash_completion.d/docker-compose
68+
# Start Sourcegraph with Docker Compose
69+
cd "${DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT}"/docker-compose
70+
docker-compose up -d --remove-orphans

0 commit comments

Comments
 (0)