From a18d3698590169cd0dbf26ffd2e73df721bbc80e Mon Sep 17 00:00:00 2001 From: dmartinez Date: Thu, 2 May 2024 14:20:08 -0700 Subject: [PATCH] Add support for reproducible builds --- .dockerignore | 1 + .gitignore | 1 + Makefile | 34 ++++++++++++++++++++++++++++++++++ VERSION.txt | 1 + artifact/.gitkeep | 0 bin/zip_build.sh | 10 ++++++++++ docker-compose.yml | 12 ++++++++++++ 7 files changed, 59 insertions(+) create mode 100644 Makefile create mode 100644 VERSION.txt create mode 100644 artifact/.gitkeep create mode 100755 bin/zip_build.sh create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore index 37a98db..0ab8bf3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,4 +6,5 @@ build cypress* Dockerfile node_modules +output README.md diff --git a/.gitignore b/.gitignore index 4d29575..75aed4e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ # production /build +/artifact/v* # misc .DS_Store diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..eb73aef --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +# This is the main interface into the repository for CI automation/reproducible builds. +# +# All targets assume they're running on a Linux or macOS host with Bash and Docker installed. +# Any other dependencies should be satisfied by containers. +# + +.DEFAULT_GOAL := help + +DEBUG = [DEBUG] +INFO = [INFO] +SUCCESS = [INFO] + +CURRENT_UID := $(shell id -u) + +compose := docker-compose + +.PHONY: all +all: build + +.PHONY: build +build: ## Build the static site from the container image + @echo "$(INFO) Building the wayfinder static site files" + $(compose) run --build -e CURRENT_UID=${CURRENT_UID} build-wayfinder + @echo "$(SUCCESS) Successfully built!" + +.PHONY: clean +clean: ## Remove build artifacts + rm -f v* + +.PHONY: help +help: ## Display this help (default) + @echo "Targets:" + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort \ + | awk 'BEGIN {FS = ":.*?## "}; {printf " %-17s%s\n", $$1, $$2}' diff --git a/VERSION.txt b/VERSION.txt new file mode 100644 index 0000000..afaf360 --- /dev/null +++ b/VERSION.txt @@ -0,0 +1 @@ +1.0.0 \ No newline at end of file diff --git a/artifact/.gitkeep b/artifact/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/bin/zip_build.sh b/bin/zip_build.sh new file mode 100755 index 0000000..3267be9 --- /dev/null +++ b/bin/zip_build.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +HOME_DIR=/usr/src/app +VERSION=v$(cat $HOME_DIR/VERSION.txt) + +cd $HOME_DIR/build + +tar -czvf $HOME_DIR/artifact/$VERSION.tar.gz * + +chown $CURRENT_UID:$CURRENT_UID $HOME_DIR/artifact/$VERSION.tar.gz \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9561de1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3.8" + +services: + + build-wayfinder: + build: + context: "." + command: sh -c "npm run build && bin/zip_build.sh" + volumes: + - type: bind + source: ./artifact + target: /usr/src/app/artifact