From 47aafb75f144a945e3979d7da308a115c4a28343 Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 18:52:00 +1000 Subject: [PATCH 01/17] Create Makefile --- Makefile | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 25 ++++++++++++++++++++++--- 2 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..daca564 --- /dev/null +++ b/Makefile @@ -0,0 +1,54 @@ +# Makefile for PixivFE + +# Variables +BINARY_NAME=pixivfe +GOFILES=$(shell find . -type f -name '*.go') + +# Environment variables (customize as needed) +export PIXIVFE_TOKEN=token_123456 +export PIXIVFE_IMAGEPROXY=pximg.cocomi.cf +export PIXIVFE_PORT=8282 + +.PHONY: all fmt build test run clean + +all: fmt build test + +fmt: + @echo "Formatting Go code..." + @go fmt ./$(shell find . -type d) + +build: + @echo "Building $(BINARY_NAME)..." + @go mod download + @go get codeberg.org/vnpower/pixivfe/v2/... + @CGO_ENABLED=0 go build -v -ldflags="-extldflags=-static" -tags netgo -o $(BINARY_NAME) + +test: + @echo "Running tests..." + @go test ./server/template + +run: build + @echo "Running $(BINARY_NAME)..." + ./$(BINARY_NAME) + +clean: + @echo "Cleaning up..." + @rm -f $(BINARY_NAME) + +# Additional target to install test script as pre-commit hook +install-pre-commit: + @echo "Installing pre-commit hook..." + @cp test.sh .git/hooks/pre-commit + @chmod +x .git/hooks/pre-commit + +# Help target +help: + @echo "Available targets:" + @echo " all - Run fmt, build, and test" + @echo " fmt - Format Go code" + @echo " build - Build the binary" + @echo " test - Run tests" + @echo " run - Build and run the binary" + @echo " clean - Remove the binary" + @echo " install-pre-commit - Install test script as pre-commit hook" + @echo " help - Show this help message" diff --git a/README.md b/README.md index bd95b8a..8d5ce24 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Prerequisites: - [Go](https://go.dev/doc/install) (to build PixivFE from source) - [Sass](https://github.com/sass/dart-sass/) (will be run by PixivFE in development mode) +- [Make](https://www.gnu.org/software/make/) (to use the Makefile) To install Dart Sass, you can choose any of the following methods. @@ -41,13 +42,31 @@ Then, run the project: # Clone the PixivFE repository git clone https://codeberg.org/VnPower/PixivFE.git && cd PixivFE -# Run in PixivFE in development mode (styles and templates reload automatically) -PIXIVFE_DEV=1 go run . +# Build the project +make build + +# Run PixivFE in development mode (styles and templates reload automatically) +PIXIVFE_DEV=1 make run ``` +## Using the Makefile + +The project includes a Makefile to simplify common development tasks. Here are the available commands: + +- `make all`: Run fmt, build, and test +- `make fmt`: Format Go code +- `make build`: Build the binary +- `make test`: Run tests +- `make run`: Build and run the binary +- `make clean`: Remove the built binary +- `make install-pre-commit`: Install test script as pre-commit hook +- `make help`: Show all available targets and their descriptions + +You can use these commands to streamline your development workflow. + ## Hosting PixivFE -You can use PixivFE for personal use! Assuming that you use an operating system that can run POSIX shell scripts, install `go`, clone this repository, modify the `run.sh` file, and profit! +You can use PixivFE for personal use! Assuming that you use an operating system that can run POSIX shell scripts, install `go`, clone this repository, and use the Makefile to build and run the project. I recommend self-hosting your own instance for personal use, instead of relying entirely on official instances. To deploy PixivFE using Docker or the compiled binary, see [Hosting PixivFE](https://pixivfe-docs.pages.dev/hosting-pixivfe/). From 7224c098f383bbbf8a2f04da8b228b07da5a1f9e Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 19:18:35 +1000 Subject: [PATCH 02/17] makefile: update .PHONY target --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index daca564..6603d25 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ export PIXIVFE_TOKEN=token_123456 export PIXIVFE_IMAGEPROXY=pximg.cocomi.cf export PIXIVFE_PORT=8282 -.PHONY: all fmt build test run clean +.PHONY: all fmt build test run clean install-pre-commit help all: fmt build test From cc66935c5867218896f1e3fcc7155d4f38270298 Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 19:18:47 +1000 Subject: [PATCH 03/17] makefile: simplify fmt command --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6603d25..363ec83 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ all: fmt build test fmt: @echo "Formatting Go code..." - @go fmt ./$(shell find . -type d) + @go fmt ./... build: @echo "Building $(BINARY_NAME)..." From 19ac031e35cff5561c4b943189ded1ce6dae96f5 Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 19:19:16 +1000 Subject: [PATCH 04/17] makefile: rm go get go get is deprecated from Go 1.17 src: https://web.archive.org/web/20240916092028/https://go.dev/doc/go-get-install-deprecation --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 363ec83..9ab0884 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,6 @@ fmt: build: @echo "Building $(BINARY_NAME)..." @go mod download - @go get codeberg.org/vnpower/pixivfe/v2/... @CGO_ENABLED=0 go build -v -ldflags="-extldflags=-static" -tags netgo -o $(BINARY_NAME) test: From 0374ec692c29345beb35ba2347242bd17dc0901a Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 19:22:15 +1000 Subject: [PATCH 05/17] makefile: rm hardcoded env vars and load from .env --- Makefile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 9ab0884..67cb469 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,8 @@ BINARY_NAME=pixivfe GOFILES=$(shell find . -type f -name '*.go') -# Environment variables (customize as needed) -export PIXIVFE_TOKEN=token_123456 -export PIXIVFE_IMAGEPROXY=pximg.cocomi.cf -export PIXIVFE_PORT=8282 +# Include environment variables from .env +include .env .PHONY: all fmt build test run clean install-pre-commit help @@ -28,7 +26,7 @@ test: run: build @echo "Running $(BINARY_NAME)..." - ./$(BINARY_NAME) + @./$(BINARY_NAME) clean: @echo "Cleaning up..." From 910bd00de20c6671830925496469512629a6ad98 Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 19:30:31 +1000 Subject: [PATCH 06/17] make run.sh executable --- run.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 run.sh diff --git a/run.sh b/run.sh old mode 100644 new mode 100755 From 94161786f7979595ab9d49a4d9bc7572d4424fa5 Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 19:38:23 +1000 Subject: [PATCH 07/17] makefile: do not fail when .env doesn't exist --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 67cb469..a90755f 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,8 @@ BINARY_NAME=pixivfe GOFILES=$(shell find . -type f -name '*.go') -# Include environment variables from .env -include .env +# Include environment variables from .env if it exists +-include .env .PHONY: all fmt build test run clean install-pre-commit help From 1ef27225cdbf07ae879ed2614d8896810362c6c8 Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 19:41:40 +1000 Subject: [PATCH 08/17] makefile: rm unnecessary gofiles var --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index a90755f..aae3865 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ # Variables BINARY_NAME=pixivfe -GOFILES=$(shell find . -type f -name '*.go') # Include environment variables from .env if it exists -include .env From 129282d010ee136e7380e6e683a605674086e59f Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 19:42:27 +1000 Subject: [PATCH 09/17] docs: suggest to run make help instead in README --- README.md | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/README.md b/README.md index 8d5ce24..989e28a 100644 --- a/README.md +++ b/README.md @@ -51,18 +51,7 @@ PIXIVFE_DEV=1 make run ## Using the Makefile -The project includes a Makefile to simplify common development tasks. Here are the available commands: - -- `make all`: Run fmt, build, and test -- `make fmt`: Format Go code -- `make build`: Build the binary -- `make test`: Run tests -- `make run`: Build and run the binary -- `make clean`: Remove the built binary -- `make install-pre-commit`: Install test script as pre-commit hook -- `make help`: Show all available targets and their descriptions - -You can use these commands to streamline your development workflow. +The project includes a Makefile to simplify common development tasks. Run `make help` to view the available commands. ## Hosting PixivFE From f3ca6302c12708524936aebd621959db10148b39 Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 20:29:07 +1000 Subject: [PATCH 10/17] Docker for reproducible Makefile --- Dockerfile.build | 20 ++++++++++++++++++++ README.md | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Dockerfile.build diff --git a/Dockerfile.build b/Dockerfile.build new file mode 100644 index 0000000..61260c9 --- /dev/null +++ b/Dockerfile.build @@ -0,0 +1,20 @@ +# Intended for creating a reproducible build environment +# Not for production use + +# Use the official Debian-based Go image as the base image +FROM golang:1.23.1-bullseye + +# Set the working directory in the container +WORKDIR /app + +# Install make, git, and any other necessary build tools +RUN apt-get update && apt-get install -y make git golang-go + +# Copy the local package files to the container's workspace +COPY . . + +# Set the entrypoint to make +ENTRYPOINT ["make"] + +# Set the default command to run when the container starts +CMD ["all"] diff --git a/README.md b/README.md index 989e28a..c14e8a5 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,30 @@ make build PIXIVFE_DEV=1 make run ``` +### Docker Build Environment + +We provide a `Dockerfile.build` to create a reproducible build environment. This Docker image is designed to run the project's Makefile consistently across different environments. + +#### Usage + +1. Build the Docker image: + + ```bash + docker build -t pixivfe-build -f Dockerfile.build . + ``` + +2. Run the container to execute the default 'make all' target: + + ```bash + docker run --rm -it -e PIXIVFE_PORT=8282 -e PIXIVFE_TOKEN=changeme -p 127.0.0.1:8282:8282 pixivfe-build + ``` + +3. Run the container with a specific make target, such as 'make run': + + ```bash + docker run --rm -it -e PIXIVFE_PORT=8282 -e PIXIVFE_TOKEN=changeme -p 127.0.0.1:8282:8282 pixivfe-build run + ``` + ## Using the Makefile The project includes a Makefile to simplify common development tasks. Run `make help` to view the available commands. From aaa780278749fb613fdcefdbae0aa0f74d2c39d0 Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 20:51:04 +1000 Subject: [PATCH 11/17] Revert "Docker for reproducible Makefile" This reverts commit 8855af2344fa76f51f0e8a1ce4faa707c9af8a64. --- Dockerfile.build | 20 -------------------- README.md | 24 ------------------------ 2 files changed, 44 deletions(-) delete mode 100644 Dockerfile.build diff --git a/Dockerfile.build b/Dockerfile.build deleted file mode 100644 index 61260c9..0000000 --- a/Dockerfile.build +++ /dev/null @@ -1,20 +0,0 @@ -# Intended for creating a reproducible build environment -# Not for production use - -# Use the official Debian-based Go image as the base image -FROM golang:1.23.1-bullseye - -# Set the working directory in the container -WORKDIR /app - -# Install make, git, and any other necessary build tools -RUN apt-get update && apt-get install -y make git golang-go - -# Copy the local package files to the container's workspace -COPY . . - -# Set the entrypoint to make -ENTRYPOINT ["make"] - -# Set the default command to run when the container starts -CMD ["all"] diff --git a/README.md b/README.md index c14e8a5..989e28a 100644 --- a/README.md +++ b/README.md @@ -49,30 +49,6 @@ make build PIXIVFE_DEV=1 make run ``` -### Docker Build Environment - -We provide a `Dockerfile.build` to create a reproducible build environment. This Docker image is designed to run the project's Makefile consistently across different environments. - -#### Usage - -1. Build the Docker image: - - ```bash - docker build -t pixivfe-build -f Dockerfile.build . - ``` - -2. Run the container to execute the default 'make all' target: - - ```bash - docker run --rm -it -e PIXIVFE_PORT=8282 -e PIXIVFE_TOKEN=changeme -p 127.0.0.1:8282:8282 pixivfe-build - ``` - -3. Run the container with a specific make target, such as 'make run': - - ```bash - docker run --rm -it -e PIXIVFE_PORT=8282 -e PIXIVFE_TOKEN=changeme -p 127.0.0.1:8282:8282 pixivfe-build run - ``` - ## Using the Makefile The project includes a Makefile to simplify common development tasks. Run `make help` to view the available commands. From d2eb3eddb89ba1b755797403ffd63526cc70f392 Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 20:53:08 +1000 Subject: [PATCH 12/17] makefile: echo commands --- Makefile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index aae3865..72a2892 100644 --- a/Makefile +++ b/Makefile @@ -12,30 +12,30 @@ all: fmt build test fmt: @echo "Formatting Go code..." - @go fmt ./... + go fmt ./... build: @echo "Building $(BINARY_NAME)..." - @go mod download - @CGO_ENABLED=0 go build -v -ldflags="-extldflags=-static" -tags netgo -o $(BINARY_NAME) + go mod download + CGO_ENABLED=0 go build -v -ldflags="-extldflags=-static" -tags netgo -o $(BINARY_NAME) test: @echo "Running tests..." - @go test ./server/template + go test ./server/template run: build @echo "Running $(BINARY_NAME)..." - @./$(BINARY_NAME) + ./$(BINARY_NAME) clean: @echo "Cleaning up..." - @rm -f $(BINARY_NAME) + rm -f $(BINARY_NAME) # Additional target to install test script as pre-commit hook install-pre-commit: @echo "Installing pre-commit hook..." - @cp test.sh .git/hooks/pre-commit - @chmod +x .git/hooks/pre-commit + cp test.sh .git/hooks/pre-commit + chmod +x .git/hooks/pre-commit # Help target help: From 3e46683054ac4ac183db62750ed20f22168de6bc Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 20:54:08 +1000 Subject: [PATCH 13/17] rm shell scripts --- fmt.sh | 2 -- run.sh | 16 ---------------- test.sh | 5 ----- 3 files changed, 23 deletions(-) delete mode 100755 fmt.sh delete mode 100755 run.sh delete mode 100755 test.sh diff --git a/fmt.sh b/fmt.sh deleted file mode 100755 index 4a55aa9..0000000 --- a/fmt.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -go fmt ./$(find -type d) \ No newline at end of file diff --git a/run.sh b/run.sh deleted file mode 100755 index 252843b..0000000 --- a/run.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -# Update the program every time you run? -# git pull - -# Visit ./doc/Environment\ Variables.go for more details -export PIXIVFE_TOKEN=token_123456 -export PIXIVFE_IMAGEPROXY=pximg.cocomi.cf -# export PIXIVFE_UNIXSOCKET=/srv/http/pages/pixivfe -export PIXIVFE_PORT=8282 - -go mod download -go get codeberg.org/vnpower/pixivfe/v2/... -CGO_ENABLED=0 GOOS=linux go build -mod=readonly -o pixivfe - -./pixivfe diff --git a/test.sh b/test.sh deleted file mode 100755 index fd6e360..0000000 --- a/test.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -go test ./server/template - -# install as pre-commit hook: -# cp test.sh ~/.git/hooks/pre-commit From becf544365c313f3b1be14fc81bf3d3490c3cfa1 Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 20:55:34 +1000 Subject: [PATCH 14/17] makefile: help target formatting --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 72a2892..0bb8581 100644 --- a/Makefile +++ b/Makefile @@ -40,11 +40,11 @@ install-pre-commit: # Help target help: @echo "Available targets:" - @echo " all - Run fmt, build, and test" - @echo " fmt - Format Go code" - @echo " build - Build the binary" - @echo " test - Run tests" - @echo " run - Build and run the binary" - @echo " clean - Remove the binary" + @echo " all - Run fmt, build, and test" + @echo " fmt - Format Go code" + @echo " build - Build the binary" + @echo " test - Run tests" + @echo " run - Build and run the binary" + @echo " clean - Remove the binary" @echo " install-pre-commit - Install test script as pre-commit hook" - @echo " help - Show this help message" + @echo " help - Show this help message" From 974fdfdbb96666bf5bdae69e955f9194d76a0a83 Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 20:59:35 +1000 Subject: [PATCH 15/17] makefile: fix pre commit hook target --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0bb8581..b4371ad 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,8 @@ clean: # Additional target to install test script as pre-commit hook install-pre-commit: @echo "Installing pre-commit hook..." - cp test.sh .git/hooks/pre-commit + echo '#!/bin/sh' > .git/hooks/pre-commit + echo 'go test ./server/template' >> .git/hooks/pre-commit chmod +x .git/hooks/pre-commit # Help target @@ -46,5 +47,5 @@ help: @echo " test - Run tests" @echo " run - Build and run the binary" @echo " clean - Remove the binary" - @echo " install-pre-commit - Install test script as pre-commit hook" + @echo " install-pre-commit - Install testing pre-commit hook" @echo " help - Show this help message" From 89f9c61dc98699c1159f933301730379bfb8812c Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 21:07:09 +1000 Subject: [PATCH 16/17] docs: update with Make instructions --- doc/hosting/hosting-pixivfe.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/hosting/hosting-pixivfe.md b/doc/hosting/hosting-pixivfe.md index 734e3a0..5c65f2b 100644 --- a/doc/hosting/hosting-pixivfe.md +++ b/doc/hosting/hosting-pixivfe.md @@ -86,20 +86,28 @@ This setup uses [Caddy](https://caddyserver.com/) as the reverse proxy. Caddy is ### 1. Setting up the repository -Clone the PixivFE repository, navigate to the directory, and install the dependencies: +Clone the PixivFE repository and navigate to the directory: ```bash git clone https://codeberg.org/VnPower/PixivFE.git && cd PixivFE -go install ``` ### 2. Configure environment variables Copy `.env.example` to `.env` and configure the variables as needed. Refer to the [Environment variables](environment-variables.md) page for more information. -### 3. Deploying PixivFE +### 3. Building and running PixivFE -Run `env $(cat .env | xargs) go run main.go` to start PixivFE. It will be accessible at `localhost:8282`. +PixivFE uses a [Makefile](https://www.gnu.org/software/make/manual/make.html#Introduction) to simplify the build and run process. + +To build and run PixivFE, use the following commands: + +```bash +make build +make run +``` + +This will build the PixivFE binary and start it. It will be accessible at `localhost:8282`. ### 4. Deploying Caddy @@ -161,8 +169,8 @@ To update PixivFE to the latest version, follow the steps below that are relevan 2. Rebuild and start PixivFE: ```bash - go install - env $(cat .env | xargs) go run main.go + make build + make run ``` ## Acknowledgements From 71e5d4a0baead0626fbf3e7a6333638613ea016b Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 16 Sep 2024 21:07:33 +1000 Subject: [PATCH 17/17] docs: fix heading --- doc/hosting/hosting-pixivfe.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/hosting/hosting-pixivfe.md b/doc/hosting/hosting-pixivfe.md index 5c65f2b..a199bd7 100644 --- a/doc/hosting/hosting-pixivfe.md +++ b/doc/hosting/hosting-pixivfe.md @@ -160,7 +160,7 @@ To update PixivFE to the latest version, follow the steps below that are relevan docker run -d --name pixivfe -p 8282:8282 --env-file .env vnpower/pixivfe:latest ``` -## Binary +### Binary 1. Pull the latest changes from the repository: ```bash