Created
January 10, 2021 12:59
-
-
Save madagra/c0311b7ecbab82d5aefe74ce09522893 to your computer and use it in GitHub Desktop.
Cloud init template for private PyPi repo on AWS
This file contains hidden or 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
data "template_cloudinit_config" "config" { | |
gzip = false | |
base64_encode = true | |
part { | |
content_type = "text/x-shellscript" | |
content = <<EOT | |
#!/bin/bash | |
sudo mkdir -p /opt/pypi_server | |
cd /opt/pypi_server | |
# create username and password for authentication | |
sudo yum update -y | |
sudo yum install -y httpd-tools | |
sudo htpasswd -b -c htpasswd ${var.pypi_username} ${var.pypi_password} | |
# launch script for the PyPi server | |
cat << EOF > ./run_pypi_server.sh | |
#!/bin/bash | |
sudo yum update -y | |
sudo yum install -y python3 | |
sudo python3 -m pip install passlib | |
sudo python3 -m pip install pypiserver | |
sudo python3 -m pypiserver -v -p 8080 -P /opt/pypi_server/htpasswd -a download,update,list /opt/pypi_server/packages | |
EOF | |
sudo chmod u+x run_pypi_server.sh | |
sudo mkdir packages | |
# add the PyPi server to the running services | |
cat << EOF > ./pypi_server.service | |
[Unit] | |
Description=Private Pypi server | |
After=network.target | |
[Service] | |
Type=simple | |
ExecStart=/opt/pypi_server/run_pypi_server.sh | |
KillMode=process | |
Restart=on-failure | |
RestartSec=42s | |
[Install] | |
WantedBy=default.target | |
EOF | |
sudo mv ./pypi_server.service /etc/systemd/system | |
sudo systemctl enable pypi_server.service | |
sudo systemctl start pypi_server.service | |
EOT | |
} | |
dynamic "part" { | |
for_each = local.user_data | |
content { | |
content_type = "text/x-shellscript" | |
content = part.value | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment