From 2f400fc3c907a2a1786be1c11252595b9f4fe4be Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sun, 8 Apr 2018 22:12:27 -0700 Subject: [PATCH] multiple environments. --- config/prod.edn | 7 ++++++- docker-compose.prod.yml | 17 ++++++++++------- docker-compose.yml | 7 +------ src/clj/auto_ap/background/mail.clj | 6 +++--- src/clj/auto_ap/handler.clj | 2 +- src/clj/auto_ap/routes/reminders.clj | 3 +-- terraform/main.tf | 11 +++++++---- terraform/prod.tfvars | 3 +++ terraform/reminders.tf | 2 +- 9 files changed, 33 insertions(+), 25 deletions(-) diff --git a/config/prod.edn b/config/prod.edn index bc59d8b9..a8d67a2c 100644 --- a/config/prod.edn +++ b/config/prod.edn @@ -1,3 +1,8 @@ {:db {:server "database"} :scheme "https" - :jwt-secret "auto ap invoices are awesome"} + :jwt-secret "auto ap invoices are awesome" + :aws-access-key-id "AKIAISQDBHDDBYVHNXMQ" + :aws-secret-access-key "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" + :aws-region "us-east-1" + :invoice-import-queue-url "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-mail-prod" + } diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 569231da..7bb0fa42 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -2,18 +2,21 @@ version: '3' services: nginx-proxy: restart: always + ports: + - "80:80" + - "443:443" volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - /opt/integreat/certs/:/etc/nginx/certs:ro - - /opt/integreat/etc/nginx/vhost.d:/etc/nginx/vhost.d - - /opt/integreat/usr/share/nginx/html:/usr/share/nginx/html + - /opt/integreat/prod/certs/:/etc/nginx/certs:ro + - /opt/integreat/prod/etc/nginx/vhost.d:/etc/nginx/vhost.d + - /opt/integreat/prod/usr/share/nginx/html:/usr/share/nginx/html letsencrypt: restart: always volumes: - /var/run/docker.sock:/var/run/docker.sock:ro - - /opt/integreat/certs/:/etc/nginx/certs - - /opt/integreat/etc/nginx/vhost.d:/etc/nginx/vhost.d - - /opt/integreat/usr/share/nginx/html:/usr/share/nginx/html + - /opt/integreat/prod/certs/:/etc/nginx/certs + - /opt/integreat/prod/etc/nginx/vhost.d:/etc/nginx/vhost.d + - /opt/integreat/prod/usr/share/nginx/html:/usr/share/nginx/html app: restart: always environment: @@ -24,4 +27,4 @@ services: database: restart: always volumes: - - /opt/integreat/var/lib/postgresql/data:/var/lib/postgresql/data + - /opt/integreat/prod/var/lib/postgresql/data:/var/lib/postgresql/data diff --git a/docker-compose.yml b/docker-compose.yml index 526eae5d..332e97a2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,9 +2,6 @@ version: '3' services: nginx-proxy: image: jwilder/nginx-proxy:alpine - ports: - - "80:80" - - "443:443" labels: - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true" volumes: @@ -26,12 +23,10 @@ services: depends_on: - database environment: - config: /usr/local/config/prod.edn + config: /usr/local/config/local.edn VIRTUAL_HOST: local.integreat.aws.brycecovertoperations.com database: image: postgres:9-alpine - ports: - - 5432:5432 environment: POSTGRES_USER: ap POSTGRES_PASSWORD: fifteen-invoices-imported! diff --git a/src/clj/auto_ap/background/mail.clj b/src/clj/auto_ap/background/mail.clj index 1a0e39ac..59a1232e 100644 --- a/src/clj/auto_ap/background/mail.clj +++ b/src/clj/auto_ap/background/mail.clj @@ -5,6 +5,7 @@ [clojure-mail.message :as message] [clojure.string :as str] [clojure.java.io :as io] + [config.core :refer [env]] [auto-ap.parse :as parse] [auto-ap.db.invoices :as invoices] [auto-ap.db.companies :as companies] @@ -20,13 +21,12 @@ Flags$Flag AuthenticationFailedException] (com.sun.mail.imap IMAPStore))) -(def queue-url "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-mail-prod") (defn process-sqs [] (try (println "Fetching messages from sqs...") (let [companies (companies/get-all)] - (doseq [message (:messages (sqs/receive-message {:queue-url queue-url + (doseq [message (:messages (sqs/receive-message {:queue-url (:invoice-import-queue-url env) :wait-time-seconds 5 :max-number-of-messages 10 #_#_:attribute-names ["All"]}))] @@ -46,7 +46,7 @@ (io/copy (:body pdf-stream) (io/file filename)) (invoices/import (parse/parse-file filename filename) companies) (io/delete-file filename)))))) - (sqs/delete-message (assoc message :queue-url queue-url )))) + (sqs/delete-message (assoc message :queue-url (:invoice-import-queue-url env) )))) (catch Exception e (println e)))) diff --git a/src/clj/auto_ap/handler.clj b/src/clj/auto_ap/handler.clj index 8ce3b04d..a797a1b7 100644 --- a/src/clj/auto_ap/handler.clj +++ b/src/clj/auto_ap/handler.clj @@ -22,7 +22,7 @@ [auto-ap.routes.auth :as auth] [amazonica.core :refer [defcredential]])) -(defcredential "AKIAINHACMVQJ6NYD26A" "FwdL4TbIC/5H/4mwhQy4iSI/eSewyPgfS1EEt6tL" "us-east-1") +(defcredential (:aws-access-key-id env) (:aws-secret-access-key env) (:aws-region env)) (defroutes static-routes (GET "/" [] (response/resource-response "index.html" {:root "public"})) diff --git a/src/clj/auto_ap/routes/reminders.clj b/src/clj/auto_ap/routes/reminders.clj index a7a6b2c2..17c73bdf 100644 --- a/src/clj/auto_ap/routes/reminders.clj +++ b/src/clj/auto_ap/routes/reminders.clj @@ -39,8 +39,7 @@ (defn find-ready-reminders [] (let [vendors (vendors/get-all) ready-reminders (reminders/get-ready)] - ready-reminders - )) + ready-reminders)) (defn send-emails [reminders] (doseq [{:keys [vendor-name email id]} reminders] diff --git a/terraform/main.tf b/terraform/main.tf index ab497c9a..69965b88 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -6,6 +6,9 @@ provider "aws" { variable "aws_secret_access_key" {} variable "aws_access_key_id" {} +variable "domain" {} +variable "base_url" {} +variable "invoice_address" {} variable "stage" {} data "aws_caller_identity" "current" {} @@ -18,13 +21,13 @@ resource "aws_ses_receipt_rule" "store" { depends_on = ["aws_ses_receipt_rule_set.main"] name = "store-${var.stage}" rule_set_name = "default-rule-set" - recipients = ["invoices@mail.integreat.aws.brycecovertoperations.com"] + recipients = ["${var.invoice_address}"] enabled = true scan_enabled = true s3_action { bucket_name = "${aws_s3_bucket.invoices.id}" - position = 0 + position = "1" } } @@ -42,7 +45,7 @@ resource "aws_s3_bucket" "invoices" { "Service": "ses.amazonaws.com" }, "Action": "s3:PutObject", - "Resource": "arn:aws:s3:::integreat-mail-prod/*", + "Resource": "arn:aws:s3:::integreat-mail-${var.stage}/*", "Condition": { "StringEquals": { "aws:Referer": "${data.aws_caller_identity.current.account_id}" @@ -64,7 +67,7 @@ resource "aws_sqs_queue" "integreat-mail" { "Effect": "Allow", "Principal": "*", "Action": "sqs:SendMessage", - "Resource": "arn:aws:sqs:*:*:integreat-mail-prod", + "Resource": "arn:aws:sqs:*:*:integreat-mail-${var.stage}", "Condition": { "ArnEquals": { "aws:SourceArn": "${aws_s3_bucket.invoices.arn}" } } diff --git a/terraform/prod.tfvars b/terraform/prod.tfvars index 42be5cb4..e565c840 100644 --- a/terraform/prod.tfvars +++ b/terraform/prod.tfvars @@ -1,3 +1,6 @@ aws_access_key_id="AKIAINHACMVQJ6NYD26A" aws_secret_access_key="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" +domain="integreat.aws.brycecovertoperations.com" +invoice_address="invoices@mail.integreat.aws.brycecovertoperations.com" +base_url="https://integreat.aws.brycecovertoperations.com" stage="prod" diff --git a/terraform/reminders.tf b/terraform/reminders.tf index 1ba7d33c..d8dceb43 100644 --- a/terraform/reminders.tf +++ b/terraform/reminders.tf @@ -46,7 +46,7 @@ EOF resource "aws_sns_topic_subscription" "send_reminders_to_service" { topic_arn = "${aws_sns_topic.reminder_topic.arn}" protocol = "https" - endpoint = "https://integreat.aws.brycecovertoperations.com/api/reminders/send" + endpoint = "${var.base_url}/api/reminders/send" endpoint_auto_confirms = true }