Last active
January 12, 2021 19:43
-
-
Save retrogradeorbit/3fb72e6538e98c6fa5fb787c64f5f80b to your computer and use it in GitHub Desktop.
build new up to date acmetool package on digital ocean droplet
This file contains hidden or 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
#!/usr/bin/env spire | |
;; spin up a digital ocean droplet | |
;; build latest acmetool | |
;; patch and update debian package | |
;; download acmetool binary and new package | |
;; destroy droplet | |
;; requirements: | |
;; spire 0.1.0-alpha.15 or above | |
;; digitalocean.clj and new-utils.clj in same directory (available in gists) | |
;; to run: | |
;; export DO_TOKEN="mydoapitoken" | |
;; spire build-acmetool.clj | |
;; you should then end up with acmetool and acmetool_0.2.1_amd64.deb | |
;; inside your local directory | |
(ns build-acmetool | |
(:require [spire.modules :as spire] | |
[spire.utils :as utils] | |
[spire.default :as default] | |
[digitalocean :as do] | |
[net-utils :as net-utils] | |
[clojure.string :as string] | |
)) | |
;; my digital ocean ssh key name (to add to the machine so I can ssh in) | |
(def digitalocean-ssh-key-name "desktop key") | |
(def ssh-key (-> (do/account-keys) | |
(do/get-key-by-name digitalocean-ssh-key-name))) | |
(def build-machine | |
{:name "build-machine" | |
:region "nyc3" | |
:size "s-1vcpu-2gb" | |
:image "ubuntu-18-04-x64" | |
:backups false | |
:ipv6 true | |
:user_data nil | |
:private_networking nil | |
:volumes nil | |
:tags ["build-acmetool"] | |
:ssh_keys [(:id ssh-key)]} | |
) | |
;; for nrepl dev | |
#_ (default/set-ssh! {:hostname (-> build-machine | |
(do/create-or-return-droplet [:name :region]) | |
(get-in [:networks :v4 0 :ip_address]) | |
) | |
:username "root"}) | |
(defn install-deps [] | |
(spire/apt :update) | |
(spire/apt :upgrade) | |
(spire/apt :install ["golang-1.10" "libcap-dev" "build-essential"])) | |
(defn build-acmetool [] | |
(spire/shell {:print true | |
:cmd "git clone https://github.com/hlandau/acmetool.git"}) | |
(spire/shell {:print true | |
:cmd "make" | |
:dir "acmetool" | |
:env {:PATH "/usr/lib/go-1.10/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"}})) | |
(defn download-acmetool [] | |
(spire/download {:src "acmetool/bin/acmetool" | |
:dest "acmetool"})) | |
(defn make-deb [] | |
(spire/shell {:cmd "apt-get -d -y install acmetool"}) | |
(spire/shell {:cmd "cp /var/cache/apt/archives/acmetool_*.deb ./"}) | |
(spire/mkdir {:path "tmp"}) | |
(when (not (utils/succeeded? (spire/stat "tmp/DEBIAN"))) | |
(spire/shell {:cmd "dpkg-deb -R acmetool_0.0.62-2_amd64.deb tmp"})) | |
(spire/shell {:cmd "cp acmetool/bin/acmetool tmp/usr/bin"}) | |
(spire/line-in-file :present {:path "tmp/DEBIAN/control" | |
:string-match "Version" | |
:line "Version: 0.2.1"}) | |
(let [md5sum (-> (spire/shell {:cmd "md5sum usr/bin/acmetool" | |
:dir "tmp"}) | |
:out | |
string/trim)] | |
(spire/line-in-file :present | |
{:path "tmp/DEBIAN/md5sums" | |
:string-match "usr/bin/acmetool" | |
:line md5sum})) | |
(spire/shell {:cmd "dpkg-deb -b tmp acmetool_0.2.1_amd64.deb"})) | |
(defn download-deb [] | |
(spire/download {:src "acmetool_0.2.1_amd64.deb" | |
:dest "./"})) | |
(defn build [] | |
(let [{:keys [networks] :as droplet} (do/create-or-return-droplet build-machine [:name :region]) | |
ip-address (get-in networks [:v4 0 :ip_address])] | |
(net-utils/wait-for-port ip-address 22) | |
(spire/ssh {:hostname ip-address | |
:username "root" | |
:accept-host-key true} | |
(install-deps) | |
(build-acmetool) | |
(download-acmetool) | |
(make-deb) | |
(download-deb)) | |
(do/delete-droplet droplet))) | |
(build) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment