-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #962 from compdemocracy/heroku-docker-deploy
Heroku docker deploy
- Loading branch information
Showing
89 changed files
with
1,504 additions
and
5,681 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TAG=dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
on: | ||
push: | ||
branches: | ||
- dev | ||
- main | ||
- edge | ||
- stable | ||
|
||
paths: | ||
- .github/workflows/deploy-preprod.yml | ||
- client-admin | ||
- client-participation | ||
- client-report | ||
|
||
|
||
jobs: | ||
deploy-admin: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- uses: actions/checkout@v2.3.4 | ||
|
||
- name: Extract branch name | ||
shell: bash | ||
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" | ||
id: extract_branch | ||
|
||
#- uses: DeLaGuardo/setup-clojure@3.2 | ||
#with: | ||
#tools-deps: 1.10.1 | ||
#cli: 1.10.1.693 | ||
#lein: 2.9.4 | ||
|
||
- name: Build | ||
# Runs all except integration tests which require database and setup/teardown | ||
run: ./bin/build-static-assets.clj | ||
|
||
#- name: Push | ||
## Runs all except integration tests which require database and setup/teardown | ||
#run: ./bin/deploy-static-assets.clj | ||
|
20 changes: 14 additions & 6 deletions
20
.github/workflows/build-nightlies.yml → .github/workflows/release-docker-images.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM alpine:latest | ||
|
||
ENV BUILD_DEPS="bash build-base libpng-dev zlib-dev autoconf automake libtool nasm curl" \ | ||
RUN_DEPS="openssh-client openjdk8-jre" | ||
|
||
WORKDIR /build | ||
COPY . . | ||
|
||
# for build scripting | ||
RUN \ | ||
bash < <(curl -s https://raw.githubusercontent.com/babashka/babashka/master/install) | ||
|
||
#apk del $BUILD_DEPS && \ | ||
#rm -rf /tmp/* /var/cache/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/usr/bin/env bb | ||
|
||
(require '[babashka.pods :as pods] | ||
'[babashka.deps :as deps] | ||
'[babashka.process :as process] | ||
'[clojure.core.async :as async] | ||
'[clojure.pprint :as pp] | ||
'[clojure.tools.cli :as cli] | ||
'[clojure.java.io :as io] | ||
'[clojure.string :as string]) | ||
|
||
|
||
;; basic example using the process library | ||
;(-> (process/process '[ls -a] {:dir "math"}) :out slurp) | ||
|
||
(def timestamp (System/currentTimeMillis)) | ||
|
||
(defn logged-command [& args] | ||
(println "Executing command:" (pr-str args)) | ||
(apply process/process args)) | ||
|
||
|
||
(defn image-name [client-dir] | ||
(str "polis/" client-dir)) | ||
|
||
(defn container-name [client-dir] | ||
(str "polis-" client-dir "-cp-container-" timestamp)) | ||
|
||
(defn build-client | ||
"Build the client container, and give it a unique name" | ||
[client-dir] | ||
(logged-command ['docker 'build '-t (image-name client-dir) '.] | ||
{:dir client-dir})) | ||
|
||
|
||
(defn run-client-container | ||
[client-dir] | ||
"Run sleep in the client container so that it is running when we try to copy stuff out of it | ||
(docker cp only works when the container is running)" | ||
(let [command (concat '[docker run --name] | ||
[(container-name client-dir) (image-name client-dir)] | ||
;; we sleep in the container so that it doesn't just shut down immediately, before we | ||
;; copy anything | ||
'[sleep 10])] | ||
(logged-command command {:dir client-dir}))) | ||
|
||
(defn clean-build | ||
"Remove local build/dist files" | ||
[client-dir] | ||
(logged-command '[rm -fr dist] {:dir client-dir})) | ||
|
||
|
||
(defn cp-client | ||
"Copy contents out of the running docker image" | ||
[client-dir] | ||
(logged-command ['docker 'cp (str (container-name client-dir) ":/app/dist/") 'dist] | ||
{:dir client-dir})) | ||
|
||
(defn monitor-execution | ||
"Monitor the execution, and return an error object if the process does not execute properly" | ||
[proc] | ||
(let [{:keys [exit out err]} @proc] | ||
(when (> exit 0) | ||
(println "PROCESS FAILED TO EXECUTE SUCCESSFULLY!")) | ||
(println "Exit status:" exit) | ||
(let [out-str (slurp out) | ||
err-str (slurp err)] | ||
(when-not (empty? out-str) | ||
(println "Std out" out-str)) | ||
(when-not (empty? err-str) | ||
(println "Std err" err-str))))) | ||
|
||
(defn stop-containers | ||
"Stop the containers, so that we can remove them" | ||
[client-dir] | ||
(logged-command ['docker 'stop (container-name client-dir)])) | ||
|
||
(defn clean-containers | ||
"Remove the old container to clean up after ourselves" | ||
[client-dir] | ||
(logged-command ['docker 'rm (container-name client-dir)])) | ||
|
||
|
||
|
||
(defn build-and-cp-client | ||
"Build the clients with docker and copy out the assets" | ||
[client-dir] | ||
;; build the client itself, and block till complete | ||
(monitor-execution (build-client client-dir)) | ||
;; start client container and let run (should have softer monitoring of this | ||
(run-client-container client-dir) | ||
;; once that is started clean the build dir | ||
(monitor-execution (build-client client-dir)) | ||
(monitor-execution (clean-build client-dir)) | ||
(monitor-execution (cp-client client-dir)) | ||
(monitor-execution (stop-containers client-dir)) | ||
(monitor-execution (clean-containers client-dir))) | ||
;; once that has completed, | ||
|
||
(def processes | ||
(for [client-dir ["client-admin" "client-participation"]];; "client-report"]] ; leaving client-report off for now | ||
(async/thread | ||
(build-and-cp-client client-dir) | ||
(println "Finished building:" client-dir)))) | ||
|
||
;; Initiate all of the processes, since for is a lazy list | ||
(doall processes) | ||
;; for each process, wait until the process completes | ||
(doseq [proc processes] | ||
(async/<!! proc)) | ||
|
||
;; QED | ||
|
Oops, something went wrong.