Deploying on AWS documentation could use improvements
Created by: sfllaw
- Issue type: Feature request
- Sourcegraph version: 2.7.6
- OS Version: N/A
- Docker version: N/A
The documentation about Deploying Sourcegraph on AWS provides a sample user-data script that works with cloud-init.
However, it only really works when the EC2 instance is first booted. On subsequent reboots, the docker image is not launched. The right way to handle this is to have systemd control the container.
We recommend the following user-data when used with an Amazon Linux 2 AMI. The latest, as of May 2018, is amzn2-ami-hvm-2017.12.0.20180328.1-x86_64-gp2
(ami-07eb707f
):
#cloud-config
repo_update: true
repo_upgrade: all
write_files:
# systemd unit file for sourcegraph/server container
- path: /etc/systemd/system/sourcegraph-container.service
content: |
[Unit]
Description=Sourcegraph Server
After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/docker start --attach sourcegraph
ExecStop=/usr/bin/docker stop --time=10 sourcegraph
[Install]
WantedBy=local.target
packages:
- docker
runcmd:
- [ /usr/bin/systemctl, daemon-reload ]
# Create directory structure for Sourcegraph data
- [ /usr/bin/mkdir, -p, /home/ec2-user/.sourcegraph/config ]
- [ /usr/bin/mkdir, -p, /home/ec2-user/.sourcegraph/data ]
# Configure and enable Docker
- [ /usr/bin/sed, -i, -e, s/1024/10240/g, /etc/sysconfig/docker ]
- [ /usr/bin/sed, -i, -e, s/4096/40960/g, /etc/sysconfig/docker ]
- [ /usr/bin/systemctl, enable, --now, docker.service ]
- [ /usr/sbin/usermod, --append, --groups=docker, ec2-user ]
# Install and enable Sourcegraph
- [ /usr/bin/docker, run, --detach,
--name=sourcegraph,
'--publish=80:7080',
'--publish=443:7443',
--restart=unless-stopped,
'--volume=/home/ec2-user/.sourcegraph/config:/etc/sourcegraph',
'--volume=/home/ec2-user/.sourcegraph/data:/var/opt/sourcegraph',
'--volume=/var/run/docker.sock:/var/run/docker.sock',
'sourcegraph/server:latest' ]
- [ /usr/bin/systemctl, enable, --now, --no-block,
sourcegraph-container.service ]
Also note that we want systemctl start --no-block
in case the Sourcegraph container takes some time to get started.