Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
GO ?= go
UID ?= $(shell id -u)
GOROOT ?= $(shell go env GOROOT)
GOPATH ?= $(shell go env GOPATH)

Expand Down Expand Up @@ -33,3 +34,9 @@ ui:
cover:
@cat tools/cover.txt | xargs go test -v -covermode=count -coverprofile=/tmp/cover.out && \
go tool cover -html=/tmp/cover.out

.PHONY: install
install:
@if [ ! -d "./target" ]; then echo "ERROR: Please build project first by calling 'make'." && exit 2; fi
@if [ "$(UID)" -ne "0" ]; then echo "ERROR: you cannot perform this operation unless you are root." && exit 3; fi
@$(SHELL) ./build/install.sh
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,15 @@ See [wiki](https://github.com/x1unix/go-playground/wiki/Docker) for usage info.

### Local instance

Service can be built and run locally (**Go 1.12+** and **Node.js** required):

```
$ git clone https://github.com/x1unix/go-playground.git
$ cd go-playground
$ make
```

To run the playground, go to `target` directory and start the server:
Service can be built and run locally (**Go 1.17+** and **Node.js** required):

```bash
$ cd target
$ ./playground -f ./data/packages.json -debug
git clone https://github.com/x1unix/go-playground.git
cd go-playground
make
sudo make install
```

Use `-help` to get information about command params

### Third-party credits

* Default playground run server provided by [play.golang.org](https://play.golang.org)
Expand Down
23 changes: 19 additions & 4 deletions build.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
GO ?= go
YARN ?= yarn
GOROOT ?= $(shell go env GOROOT)
TOOLS ?= ./tools
PUBLIC_DIR ?= $(UI)/public
Expand All @@ -8,6 +9,20 @@ WEBWORKER_PKG ?= ./cmd/webworker
clean:
@echo ":: Cleanup..." && rm -rf $(TARGET) && rm -rf $(UI)/build

.PHONY:check-go
check-go:
@if ! command -v $(GO) >/dev/null 2>&1 ; then\
echo "ERROR: '$(GO)' binary not found. Please ensure that Go is installed or specify binary path with 'GO' variable." && \
exit 1; \
fi;

.PHONY:check-yarn
check-yarn:
@if ! command -v $(YARN) >/dev/null 2>&1 ; then\
echo "ERROR: '$(YARN)' binary not found. Please ensure that Node.js and Yarn are installed or specify binary path with 'YARN' variable." && \
exit 1; \
fi;

# Build targets
.PHONY: collect-meta
collect-meta:
Expand All @@ -17,17 +32,17 @@ collect-meta:
.PHONY:preinstall
preinstall:
@echo ":: Checking and installing dependencies..." && \
cd $(UI) && yarn install --silent
cd $(UI) && $(YARN) install --silent

.PHONY:build-server
build-server:
@echo ":: Building server..." && \
go build -o $(TARGET)/playground $(PKG)
$(GO) build -o $(TARGET)/playground $(PKG)

.PHONY:build-ui
build-ui:
@echo ":: Building UI..." && \
cd $(UI) && yarn build
cd $(UI) && $(YARN) build

.PHONY:build-webworker
build-webworker:
Expand All @@ -36,7 +51,7 @@ build-webworker:
cp "$(GOROOT)/misc/wasm/wasm_exec.js" $(PUBLIC_DIR)

.PHONY: build
build: clean preinstall collect-meta build-server build-webworker build-ui
build: check-go check-yarn clean preinstall collect-meta build-server build-webworker build-ui
@echo ":: Copying assets..." && \
cp -rfv ./data $(TARGET)/data && \
mv -v $(UI)/build $(TARGET)/public && \
Expand Down
17 changes: 17 additions & 0 deletions build/better-go-playground.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Better Go Playground
After=network.target
StartLimitIntervalSec=10
StartLimitBurst=5

[Service]
Type=simple
User=go-playground
WorkingDirectory=/opt/better-go-playground
ExecStart=/opt/better-go-playground/playground -f /opt/better-playground/data/packages.json
Restart=on-failure
LimitNOFILE=1048576
RestartSec=5

[Install]
WantedBy=multi-user.target
17 changes: 0 additions & 17 deletions build/go-playground.service

This file was deleted.

28 changes: 28 additions & 0 deletions build/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env sh
set -e

SVC_NAME='better-go-playground'
SVC_USER='go-playground'
DST_DIR='/opt/go-playground'

if [ "$(uname -s)" != "Linux" ]; then
echo "ERROR: This installation script doesn't support $(uname -s). Only Linux systems are supported."
exit 4
fi

echo ":: Creating a user '$SVC_USER'..."
useradd -m --system go-playground

echo ":: Copying files..."
cp -rfv ./target "$DST_DIR"
chown -R -v "$SVC_USER:$SVC_USER" "$DST_DIR"
chmod +x "$DST_DIR/playground"

echo ":: Installing service..."
cp -fv "./build/$SVC_NAME.service" /etc/systemd/system
systemctl daemon reload

echo ":: Starting service..."
systemctl enable --now "$SVC_NAME"

echo "Installation finished. Use 'systemctl start|stop|restart|status $SVC_NAME' to start, stop or restart the service."
51 changes: 36 additions & 15 deletions data/packages.json

Large diffs are not rendered by default.