aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-11-20 07:20:15 +0100
committerTeddy Wing2018-11-20 07:20:15 +0100
commit7d7ac8d747be198088664e45e5423919d9876651 (patch)
treed76fbd483b96f4425653143ae739f9f835939a3e
parent3002290d98c31dc941b33946197e7f58c7ff9dad (diff)
downloaddome-key-web-7d7ac8d747be198088664e45e5423919d9876651.tar.bz2
license-generator: Use compile-time environment variables
For whatever reason, the environment variables in my `.htaccess` weren't getting passed to my FastCGI executables on my production server. Wasn't sure how to get them passed to the programs, so decided instead to compile the env variables into the binaries. To do that, we source the environment file before building the release builds in the Docker container.
-rw-r--r--.htaccess3
-rw-r--r--Makefile7
-rw-r--r--license-generator/src/database.rs5
-rw-r--r--license-generator/src/logger.rs4
4 files changed, 7 insertions, 12 deletions
diff --git a/.htaccess b/.htaccess
index 186a57f..d9278c8 100644
--- a/.htaccess
+++ b/.htaccess
@@ -1,6 +1,3 @@
-SetEnv LOG_FILE "license_generator.log"
-SetEnv DATABASE_URL "mysql://localhost:3306/dome_key"
-
ErrorDocument 404 /404.html
diff --git a/Makefile b/Makefile
index a93270d..6ba245f 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ internal_error.html: internal_error.in.html
# Compile binaries for Linux
license-generator/target/release/fulfillment \
-license-generator/target/release/license:
+license-generator/target/release/license: production-config/env
docker run \
--rm \
--interactive \
@@ -21,7 +21,10 @@ license-generator/target/release/license:
--volume $$PWD/license-generator:/app \
--workdir /app \
rust:1.30.1-trusty \
- cargo build --release
+ bash -c " \
+ source ../production-config/env; \
+ cargo build --release \
+ "
.PHONY: deploy
deploy: license-generator/target/release/fulfillment \
diff --git a/license-generator/src/database.rs b/license-generator/src/database.rs
index 478c97e..85683e9 100644
--- a/license-generator/src/database.rs
+++ b/license-generator/src/database.rs
@@ -1,12 +1,9 @@
-use std::env;
-
use mysql;
use errors::*;
pub fn get_database_pool() -> Result<mysql::Pool> {
- let connection_url = env::var("DATABASE_URL")
- .chain_err(|| "DATABASE_URL environment variable not found")?;
+ let connection_url = env!("DATABASE_URL");
let pool = mysql::Pool::new_manual(4, 15, connection_url)?;
Ok(pool)
diff --git a/license-generator/src/logger.rs b/license-generator/src/logger.rs
index 1b6e07b..d286808 100644
--- a/license-generator/src/logger.rs
+++ b/license-generator/src/logger.rs
@@ -1,4 +1,3 @@
-use std::env;
use std::fs::OpenOptions;
use fastcgi;
@@ -7,8 +6,7 @@ use simplelog::{Config, LevelFilter, WriteLogger};
use errors::*;
pub fn init() -> Result<()> {
- let log_file_path = env::var("LOG_FILE")
- .chain_err(|| "LOG_FILE environment variable not found")?;
+ let log_file_path = env!("LOG_FILE");
let log_file = OpenOptions::new()
.append(true)