pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

commit f637dab7a5718d06db0ad7617ee94fce30fdd740
parent e7e2e87c22b15e44a05e48230a3d21026af9a56f
Author: pyratebeard <root@pyratebeard.net>
Date:   Sun, 23 Jan 2022 21:44:42 +0000

make_it_happen

Diffstat:
Aentry/make_it_happen.md | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 111 insertions(+), 0 deletions(-)

diff --git a/entry/make_it_happen.md b/entry/make_it_happen.md @@ -0,0 +1,111 @@ +A while I ago I saw [this tweet](https://twitter.com/silascutler/status/1353385026994511872?s=19) by @silascutler who started using `make` to run `docker` commands. + +I was intrigued so I made a similar Makefile and tried using it when using Docker +``` +override TAG = $(shell basename $$PWD) +VER := latest +IMAGE_ID = $(shell eval sudo docker images -qa ${TAG} | head -n 1) + +.PHONY: build test buildtest deploy + +build: + sudo docker build -t ${TAG}:${VER} . + +test: + sudo docker run -d ${TAG}:${VER} + +buildtest: + sudo docker build -t ${TAG}:${VER} . + sudo docker run -d ${TAG}:${VER} + +deploy: + @echo ${IMAGE_ID} + sudo docker tag ${IMAGE_ID} pyratebeard/${TAG}:latest + sudo docker push pyratebeard/${TAG}:${VER} +``` + +This Makefile will use the directory name as the container tag if not specified. I did it that way so I can have one Makefile and symlink it into every project directory. The version is set to "latest" unless otherwise. + +The rest is pretty straight forward. If you incant `make build` then a container will be built from the current directory. If you incant `make test` then the container will be started up... for testing. You can probably guess what `make buildtest` does, and then `make deploy` will tag the latest build for the remote repo and push it up. + +After using this for a while I thought it was handy enough and decided to try it with a few other tools. + +I wrote this Makefile for use with `terraform` +``` +NAME := test +VARS := terraform + +.PHONY: plan planapply refresh destroy clean + +init: + terraform init + +plan: init + terraform plan -var-file=${VARS}.tfvars -out ${NAME}.tfplan + +apply: + terraform apply -auto-approve -state-out=${NAME}.tfstate ${NAME}.tfplan + +planapply: init + terraform plan -var-file=${VARS}.tfvars -out ${NAME}.tfplan + terraform apply -auto-approve -state-out=${NAME}.tfstate ${NAME}.tfplan + +refresh: + terraform refresh -state=${NAME}.tfstate + +destroy: refresh + terraform destroy -var-file=${VARS}.tfvars -state=${NAME}.tfstate + +clean: destroy + rm -f ${NAME}.tf{plan,state{,.backup}} +``` + + + + + + + + + +Then I got more adventurous and decided to write a Makefile for use with my `drist` modules (if you're not sure what `drist` is you can read [my post](https://log.pyratebeard.net/entry/20210305-the_usefulness_of_drist.html) about it) +``` +ERVER := ../inventory +FILESDIR = files + +.PHONY: patch pkgs create_user ssh_keys new_server sshd_config fail2ban dots + +# https://blog.melski.net/2010/11/30/makefile-hacks-print-the-value-of-any-variable/ +env-%: + cd $* ; if [ ! -d ${FILESDIR} ] ; then mkdir ${FILESDIR} ; fi + cp env $*/${FILESDIR} + +patch: + cd patch ; drist ${SERVER} + +pkgs: + cd packages ; drist ${SERVER} + +create_user: env-create_user + cd create_user ; drist-root ${SERVER} + +ssh_keys: + cd ssh_keys ; drist ${SERVER} + +new_server: env-ssh_keys + cd create_user ; drist-root ${SERVER} + cd ssh_keys ; drist-root ${SERVER} + +sshd_config: env-sshd_config + cd sshd_config ; drist ${SERVER} + +fail2ban: + cd fail2ban ; drist ${SERVER} + +dots: + cd deploy_dots ; drist ${SERVER} + +secure: sshd_config fail2ban + +commission: new_server patch pkgs secure dots +```