Skip to content

Commit

Permalink
Merge pull request #1301 from compdemocracy/heroku-docker-deploy
Browse files Browse the repository at this point in the history
Heroku docker deploy
  • Loading branch information
metasoarous committed Apr 19, 2022
2 parents 796f997 + c927b5f commit cb081c1
Show file tree
Hide file tree
Showing 29 changed files with 37,035 additions and 271 deletions.
96 changes: 86 additions & 10 deletions Dockerfile
@@ -1,14 +1,90 @@
FROM alpine:latest
ARG TAG=dev

ENV BUILD_DEPS="bash build-base libpng-dev zlib-dev autoconf automake libtool nasm curl" \
RUN_DEPS="openssh-client openjdk8-jre"
# polis-client-admin
# Gulp v3 stops us from upgrading beyond Node v11
FROM docker.io/node:11.15.0-alpine

WORKDIR /build
COPY . .
WORKDIR /client-admin/app

# for build scripting
RUN \
bash < <(curl -s https://raw.githubusercontent.com/babashka/babashka/master/install)
RUN apk add git --no-cache

COPY client-admin/package*.json ./
RUN npm install

COPY client-admin/polis.config.template.js polis.config.js
# If polis.config.js exists on host, will override template here.
COPY client-admin/. .

ARG GIT_HASH
RUN npm run deploy:prod


# polis-client-participation
# # Gulp v3 stops us from upgrading beyond Node v11
FROM docker.io/node:11.15.0-alpine

WORKDIR /client-participation/app

RUN apk add --no-cache --virtual .build \
g++ git make python

# Allow global npm installs in Docker
RUN npm config set unsafe-perm true

# Upgrade npm v6.7.0 -> v6.9.2 to alias multiple pkg versions.
# See: https://stackoverflow.com/a/56134858/504018
RUN npm install -g npm@6.9.2

COPY client-participation/package*.json ./

RUN npm ci

RUN apk del .build

COPY client-participation/polis.config.template.js polis.config.js
# If polis.config.js exists on host, will override template here.
COPY client-participation/. .

ARG GIT_HASH
ARG BABEL_ENV=production

RUN npm run deploy:prod


# polis-client-report
# Gulp v3 stops us from upgrading beyond Node v11
FROM docker.io/node:11.15.0-alpine

WORKDIR /client-report/app

RUN apk add git --no-cache

COPY client-report/package*.json ./
RUN npm ci

COPY client-report/polis.config.template.js polis.config.js
# If polis.config.js exists on host, will override template here.
COPY client-report/. .

ARG GIT_HASH
RUN npm run deploy:prod


#FROM docker.io/node:16.9.0-alpine
FROM docker.io/babashka/babashka

RUN apt-get update && apt-get -y install openjdk-16-jre


RUN mkdir /app/

WORKDIR /app/

COPY ./bin/ ./bin/

COPY --from=0 /client-admin/app/dist/ /app/client-admin/dist
COPY --from=1 /client-participation/app/build/ /app/client-participation/dist
COPY --from=2 /client-report/app/build/ /app/client-report/dist

CMD ./bin/deploy-static-assets.clj --bucket $STATIC_ASSET_DEPLOY_BUCKET

#apk del $BUILD_DEPS && \
#rm -rf /tmp/* /var/cache/*
52 changes: 32 additions & 20 deletions bin/deploy-static-assets.clj
Expand Up @@ -9,22 +9,28 @@
'[clojure.java.io :as io]
'[clojure.string :as string])

(pods/load-pod 'org.babashka/postgresql "0.0.1")
(pods/load-pod 'org.babashka/aws "0.0.5")
(pods/load-pod 'org.babashka/postgresql "0.0.7")
(pods/load-pod 'org.babashka/aws "0.0.6")
(deps/add-deps '{:deps {honeysql/honeysql {:mvn/version "1.0.444"}}})

(require '[pod.babashka.postgresql :as pg]
'[honeysql.core :as hsql]
'[honeysql.helpers :as hsqlh]
'[pod.babashka.aws :as aws])
'[pod.babashka.aws :as aws]
'[pod.babashka.aws.credentials :as aws-creds])

;; Should move this to arg parsing if and when available
(def region (or (System/getenv "AWS_REGION")
"us-east-1"))

(def creds-provider
(aws-creds/basic-credentials-provider
{:access-key-id (System/getenv "AWS_ACCESS_KEY")
:secret-access-key (System/getenv "AWS_SECRET_KEY")}))

(def s3-client
"The s3 client for this process"
(aws/client {:api :s3 :region region}))
(aws/client {:api :s3 :region region :credentials-provider creds-provider}))

;; list available s3 actions
;(map first (aws/ops s3-client))
Expand Down Expand Up @@ -96,7 +102,7 @@

(defn latest-version [cache-dir]
(->> (.listFiles (io/file cache-dir))
(sort-by #(mapv try-int (string/split % #"_")))
(sort-by #(mapv try-int (string/split (str %) #"_")))
(last)))

;(latest-version "participation-client/dist/cached")
Expand Down Expand Up @@ -205,15 +211,14 @@

(def concurrent-requests 12)

(println "arg" (pr-str (first *command-line-args*)))
(def bucket
(case (first *command-line-args*)
(defn get-bucket [bucket-arg]
(case bucket-arg
"PRODUCTION" "pol.is"
;; else
"preprod.pol.is"))

("preprod" "edge") "preprod.pol.is"
bucket-arg))

(def responses
(defn responses [bucket]
(let [requests (mapcat (partial spec-requests bucket)
deploy-specs)
output-chan (async/chan concurrent-requests)]
Expand All @@ -223,18 +228,25 @@
(async/to-chan requests))
(async/<!! (async/into [] output-chan))))

(def errors
(defn errors [responses]
(remove (comp :ETag second)
responses))

(if (not-empty errors)
(do
(println "Problem processing" (count errors) "requests")
(doseq [[request response] errors]
(println "Problem processing request:" request)
(pp/pprint response)))
(println "Deploy completed without error."))

(defn -main [& {:as opts-map :strs [--bucket]}]
(let [bucket (get-bucket --bucket)
_ (println "Deploying static assets to bucket:" bucket)
responses (responses bucket)
errors (errors responses)]
(if (not-empty errors)
(do
(println "Problem processing" (count errors) "requests")
(doseq [[request response] errors]
(println "Problem processing request:" request)
(pp/pprint response)))
(println "Deploy completed without error."))))


(apply -main *command-line-args*)

;; QED

2 changes: 1 addition & 1 deletion client-admin/Dockerfile
@@ -1,5 +1,5 @@
# Gulp v3 stops us from upgrading beyond Node v11
FROM node:11.15.0-alpine
FROM docker.io/node:11.15.0-alpine

WORKDIR /app

Expand Down

0 comments on commit cb081c1

Please sign in to comment.