Skip to content

Commit

Permalink
Maintain .env config between builds
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubz committed Feb 9, 2020
1 parent 0a2b210 commit 41faf37
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions .sandstorm/build.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
#!/bin/bash
set -euo pipefail

# Save or create an .env file.
if [ -f /opt/app/babybuddy/.env ]; then
mv /opt/app/babybuddy/.env /opt/app
else
SECRET_KEY=$(python -c 'import random; result = "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)]); print(result)')
cat <<EOF > /opt/app/.env
DJANGO_SETTINGS_MODULE=babybuddy.settings.sandstorm
SECRET_KEY=$SECRET_KEY
EOF
fi

# Get application code.
cd /opt/app
rm -rf babybuddy
git clone https://github.com/babybuddy/babybuddy.git

# Set up required application environment variables.
SECRET_KEY=$(python -c 'import random; result = "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)]); print(result)')
cat <<EOF > /opt/app/babybuddy/.env
DJANGO_SETTINGS_MODULE=babybuddy.settings.sandstorm
SECRET_KEY=$SECRET_KEY
EOF

# Checkout desired version and apply Sandstorm patch.
VERSION=$(grep -oE 'appMarketingVersion = \(defaultText = "(.+)"' /opt/app/.sandstorm/sandstorm-pkgdef.capnp | cut -d '"' -f2)
cd /opt/app/babybuddy
git add --all
git checkout -f v"${VERSION}"
git apply /opt/app/sandstorm.patch

# Move .env file in to application directory.
mv /opt/app/.env /opt/app/babybuddy/.env

# Set up virtual environment.
VENV=/opt/app/babybuddy/.venv
if [ ! -d $VENV ] ; then
Expand Down

0 comments on commit 41faf37

Please sign in to comment.