riju/Makefile

103 lines
2.4 KiB
Makefile

SHELL := bash
.SHELLFLAGS := -o pipefail -euc
export PATH := bin:$(PATH)
-include .env
export
BUILD := build/$(T)/$(L)
DEB := riju-$(T)-$(L).deb
S3_DEBS := s3://$(S3_BUCKET_BASE)-debs
S3_DEB := $(S3_DEBS)/debs/$(DEB)
S3_HASH := $(S3_DEBS)/hashes/riju-$(T)-$(L)
.PHONY: help
help:
@echo "usage:"
@echo
@cat Makefile | \
grep -E '[.]PHONY|[#]##' | \
sed -E 's/[.]PHONY: */ make /' | \
sed -E 's/[#]## *(.+)/\n (\1)\n/'
### Build things locally
.PHONY: image
image:
@: $${I}
ifeq ($(I),composite)
node src/build-composite-image.js
else
docker build . -f docker/$(I)/Dockerfile -t riju:$(I) --pull
endif
.PHONY: script
script:
@: $${L} $${T}
mkdir -p $(BUILD)
node src/make-script.js --lang $(L) --type $(T) > $(BUILD)/build.bash
chmod +x $(BUILD)/build.bash
.PHONY: pkg
pkg:
@: $${L} $${T}
rm -rf $(BUILD)/src $(BUILD)/pkg
mkdir -p $(BUILD)/src $(BUILD)/pkg
cd $(BUILD)/src && pkg="$(PWD)/$(BUILD)/pkg" ../build.bash
fakeroot dpkg-deb --build $(BUILD)/pkg $(BUILD)/$(DEB)
### Run things inside Docker
VOLUME_MOUNT ?= $(PWD)
.PHONY: shell
shell:
@: $${I}
ifeq ($(I),admin)
docker run -it --rm --network host -v $(VOLUME_MOUNT):/src -v /var/run/docker.sock:/var/run/docker.sock -v $(HOME)/.aws:/var/riju/.aws:ro -e AWS_REGION -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e VOLUME_MOUNT=$(VOLUME_MOUNT) riju:$(I)
else
docker run -it --rm -v $(VOLUME_MOUNT):/src riju:$(I)
endif
.PHONY: install
install:
@: $${L} $${T}
[[ -z "$$(ls -A /var/lib/apt/lists)" ]] && sudo apt update
sudo apt reinstall -y ./$(BUILD)/$(DEB)
### Fetch things from registries
.PHONY: pull
pull:
@: $${I} $${DOCKER_REPO_BASE}
docker pull $(DOCKER_REPO_BASE):$(I)
docker tag $(DOCKER_REPO_BASE):$(I) riju:$(I)
.PHONY: download
download:
@: $${L} $${T} $${S3_BUCKET_BASE}
mkdir -p $(BUILD)
aws s3 cp $(S3_DEB) $(BUILD)/$(DEB)
### Publish things to registries
.PHONY: push
push:
@: $${I} $${DOCKER_REPO_BASE}
docker tag riju:$(I) $(DOCKER_REPO_BASE):$(I)
docker push $(DOCKER_REPO_BASE):$(I)
.PHONY: upload
upload:
@: $${L} $${T} $${S3_BUCKET_BASE}
hash=$$(dpkg-deb -f $(BUILD)/$(DEB) Riju-Script-Hash); test $${hash}; aws s3 cp - $(S3_HASH)/$${hash} < /dev/null
aws s3 cp $(BUILD)/$(DEB) $(S3_DEB)
### Miscellaneous
.PHONY: dockerignore
dockerignore:
echo "# This file is generated by 'make dockerignore', do not edit." > .dockerignore
cat .gitignore | sed 's#^#**/#' >> .dockerignore