multiple environments.

This commit is contained in:
Bryce Covert
2018-04-08 22:12:27 -07:00
parent 9dabb633a7
commit 2f400fc3c9
9 changed files with 33 additions and 25 deletions

View File

@@ -1,3 +1,8 @@
{:db {:server "database"} {:db {:server "database"}
:scheme "https" :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"
}

View File

@@ -2,18 +2,21 @@ version: '3'
services: services:
nginx-proxy: nginx-proxy:
restart: always restart: always
ports:
- "80:80"
- "443:443"
volumes: volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro - /var/run/docker.sock:/tmp/docker.sock:ro
- /opt/integreat/certs/:/etc/nginx/certs:ro - /opt/integreat/prod/certs/:/etc/nginx/certs:ro
- /opt/integreat/etc/nginx/vhost.d:/etc/nginx/vhost.d - /opt/integreat/prod/etc/nginx/vhost.d:/etc/nginx/vhost.d
- /opt/integreat/usr/share/nginx/html:/usr/share/nginx/html - /opt/integreat/prod/usr/share/nginx/html:/usr/share/nginx/html
letsencrypt: letsencrypt:
restart: always restart: always
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro - /var/run/docker.sock:/var/run/docker.sock:ro
- /opt/integreat/certs/:/etc/nginx/certs - /opt/integreat/prod/certs/:/etc/nginx/certs
- /opt/integreat/etc/nginx/vhost.d:/etc/nginx/vhost.d - /opt/integreat/prod/etc/nginx/vhost.d:/etc/nginx/vhost.d
- /opt/integreat/usr/share/nginx/html:/usr/share/nginx/html - /opt/integreat/prod/usr/share/nginx/html:/usr/share/nginx/html
app: app:
restart: always restart: always
environment: environment:
@@ -24,4 +27,4 @@ services:
database: database:
restart: always restart: always
volumes: volumes:
- /opt/integreat/var/lib/postgresql/data:/var/lib/postgresql/data - /opt/integreat/prod/var/lib/postgresql/data:/var/lib/postgresql/data

View File

@@ -2,9 +2,6 @@ version: '3'
services: services:
nginx-proxy: nginx-proxy:
image: jwilder/nginx-proxy:alpine image: jwilder/nginx-proxy:alpine
ports:
- "80:80"
- "443:443"
labels: labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true" - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
volumes: volumes:
@@ -26,12 +23,10 @@ services:
depends_on: depends_on:
- database - database
environment: environment:
config: /usr/local/config/prod.edn config: /usr/local/config/local.edn
VIRTUAL_HOST: local.integreat.aws.brycecovertoperations.com VIRTUAL_HOST: local.integreat.aws.brycecovertoperations.com
database: database:
image: postgres:9-alpine image: postgres:9-alpine
ports:
- 5432:5432
environment: environment:
POSTGRES_USER: ap POSTGRES_USER: ap
POSTGRES_PASSWORD: fifteen-invoices-imported! POSTGRES_PASSWORD: fifteen-invoices-imported!

View File

@@ -5,6 +5,7 @@
[clojure-mail.message :as message] [clojure-mail.message :as message]
[clojure.string :as str] [clojure.string :as str]
[clojure.java.io :as io] [clojure.java.io :as io]
[config.core :refer [env]]
[auto-ap.parse :as parse] [auto-ap.parse :as parse]
[auto-ap.db.invoices :as invoices] [auto-ap.db.invoices :as invoices]
[auto-ap.db.companies :as companies] [auto-ap.db.companies :as companies]
@@ -20,13 +21,12 @@
Flags$Flag AuthenticationFailedException] Flags$Flag AuthenticationFailedException]
(com.sun.mail.imap IMAPStore))) (com.sun.mail.imap IMAPStore)))
(def queue-url "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-mail-prod")
(defn process-sqs [] (defn process-sqs []
(try (try
(println "Fetching messages from sqs...") (println "Fetching messages from sqs...")
(let [companies (companies/get-all)] (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 :wait-time-seconds 5
:max-number-of-messages 10 :max-number-of-messages 10
#_#_:attribute-names ["All"]}))] #_#_:attribute-names ["All"]}))]
@@ -46,7 +46,7 @@
(io/copy (:body pdf-stream) (io/file filename)) (io/copy (:body pdf-stream) (io/file filename))
(invoices/import (parse/parse-file filename filename) companies) (invoices/import (parse/parse-file filename filename) companies)
(io/delete-file filename)))))) (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 (catch Exception e
(println e)))) (println e))))

View File

@@ -22,7 +22,7 @@
[auto-ap.routes.auth :as auth] [auto-ap.routes.auth :as auth]
[amazonica.core :refer [defcredential]])) [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 (defroutes static-routes
(GET "/" [] (response/resource-response "index.html" {:root "public"})) (GET "/" [] (response/resource-response "index.html" {:root "public"}))

View File

@@ -39,8 +39,7 @@
(defn find-ready-reminders [] (defn find-ready-reminders []
(let [vendors (vendors/get-all) (let [vendors (vendors/get-all)
ready-reminders (reminders/get-ready)] ready-reminders (reminders/get-ready)]
ready-reminders ready-reminders))
))
(defn send-emails [reminders] (defn send-emails [reminders]
(doseq [{:keys [vendor-name email id]} reminders] (doseq [{:keys [vendor-name email id]} reminders]

View File

@@ -6,6 +6,9 @@ provider "aws" {
variable "aws_secret_access_key" {} variable "aws_secret_access_key" {}
variable "aws_access_key_id" {} variable "aws_access_key_id" {}
variable "domain" {}
variable "base_url" {}
variable "invoice_address" {}
variable "stage" {} variable "stage" {}
data "aws_caller_identity" "current" {} data "aws_caller_identity" "current" {}
@@ -18,13 +21,13 @@ resource "aws_ses_receipt_rule" "store" {
depends_on = ["aws_ses_receipt_rule_set.main"] depends_on = ["aws_ses_receipt_rule_set.main"]
name = "store-${var.stage}" name = "store-${var.stage}"
rule_set_name = "default-rule-set" rule_set_name = "default-rule-set"
recipients = ["invoices@mail.integreat.aws.brycecovertoperations.com"] recipients = ["${var.invoice_address}"]
enabled = true enabled = true
scan_enabled = true scan_enabled = true
s3_action { s3_action {
bucket_name = "${aws_s3_bucket.invoices.id}" bucket_name = "${aws_s3_bucket.invoices.id}"
position = 0 position = "1"
} }
} }
@@ -42,7 +45,7 @@ resource "aws_s3_bucket" "invoices" {
"Service": "ses.amazonaws.com" "Service": "ses.amazonaws.com"
}, },
"Action": "s3:PutObject", "Action": "s3:PutObject",
"Resource": "arn:aws:s3:::integreat-mail-prod/*", "Resource": "arn:aws:s3:::integreat-mail-${var.stage}/*",
"Condition": { "Condition": {
"StringEquals": { "StringEquals": {
"aws:Referer": "${data.aws_caller_identity.current.account_id}" "aws:Referer": "${data.aws_caller_identity.current.account_id}"
@@ -64,7 +67,7 @@ resource "aws_sqs_queue" "integreat-mail" {
"Effect": "Allow", "Effect": "Allow",
"Principal": "*", "Principal": "*",
"Action": "sqs:SendMessage", "Action": "sqs:SendMessage",
"Resource": "arn:aws:sqs:*:*:integreat-mail-prod", "Resource": "arn:aws:sqs:*:*:integreat-mail-${var.stage}",
"Condition": { "Condition": {
"ArnEquals": { "aws:SourceArn": "${aws_s3_bucket.invoices.arn}" } "ArnEquals": { "aws:SourceArn": "${aws_s3_bucket.invoices.arn}" }
} }

View File

@@ -1,3 +1,6 @@
aws_access_key_id="AKIAINHACMVQJ6NYD26A" aws_access_key_id="AKIAINHACMVQJ6NYD26A"
aws_secret_access_key="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" aws_secret_access_key="FwdL4TbIC/5H/4mwhQy4iSI/eSewyPgfS1EEt6tL"
domain="integreat.aws.brycecovertoperations.com"
invoice_address="invoices@mail.integreat.aws.brycecovertoperations.com"
base_url="https://integreat.aws.brycecovertoperations.com"
stage="prod" stage="prod"

View File

@@ -46,7 +46,7 @@ EOF
resource "aws_sns_topic_subscription" "send_reminders_to_service" { resource "aws_sns_topic_subscription" "send_reminders_to_service" {
topic_arn = "${aws_sns_topic.reminder_topic.arn}" topic_arn = "${aws_sns_topic.reminder_topic.arn}"
protocol = "https" protocol = "https"
endpoint = "https://integreat.aws.brycecovertoperations.com/api/reminders/send" endpoint = "${var.base_url}/api/reminders/send"
endpoint_auto_confirms = true endpoint_auto_confirms = true
} }