Merge pull request 'Create Makefile' (#98) from perennial/PixivFE:create-makefile into v2

Reviewed-on: https://codeberg.org/VnPower/PixivFE/pulls/98
This commit is contained in:
VnPower
2024-09-16 12:23:51 +00:00
6 changed files with 77 additions and 33 deletions
+51
View File
@@ -0,0 +1,51 @@
# Makefile for PixivFE
# Variables
BINARY_NAME=pixivfe
# Include environment variables from .env if it exists
-include .env
.PHONY: all fmt build test run clean install-pre-commit help
all: fmt build test
fmt:
@echo "Formatting Go code..."
go fmt ./...
build:
@echo "Building $(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
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..."
echo '#!/bin/sh' > .git/hooks/pre-commit
echo 'go test ./server/template' >> .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 testing pre-commit hook"
@echo " help - Show this help message"
+11 -3
View File
@@ -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,20 @@ 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 <other_environment_variables> go run .
# Build the project
make build
# Run PixivFE in development mode (styles and templates reload automatically)
PIXIVFE_DEV=1 <other_environment_variables> make run
```
## Using the Makefile
The project includes a Makefile to simplify common development tasks. Run `make help` to view the available commands.
## 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/).
+15 -7
View File
@@ -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
@@ -152,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
@@ -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
-2
View File
@@ -1,2 +0,0 @@
#!/bin/sh
go fmt ./$(find -type d)
-16
View File
@@ -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
-5
View File
@@ -1,5 +0,0 @@
#!/bin/sh
go test ./server/template
# install as pre-commit hook:
# cp test.sh ~/.git/hooks/pre-commit