diff --git a/Dockerfile b/Dockerfile index fc5a032..3c71a3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,23 @@ -FROM alpine:3.19 AS build +FROM alpine:3.19 AS base RUN apk update && \ - apk add --no-cache \ - make \ - gcc \ - musl-dev \ - libstdc++ + apk add --no-cache \ + make \ + shadow \ + openssl \ + openssh \ + curl \ + wget \ + git \ + gnupg \ + xz \ + gcc \ + musl-dev \ + libstdc++ COPY --from=golang:1.21-alpine /usr/local/go/ /usr/local/go/ ENV PATH="/usr/local/go/bin:${PATH}" +ENV CGO_ENABLED=0 COPY --from=node:20-alpine /usr/local/ /usr/local/ ENV NODE_PATH="/usr/local/lib/node_modules" @@ -18,10 +27,21 @@ WORKDIR /opengist COPY . . + +FROM base AS dev + +EXPOSE 6157 2222 16157 +VOLUME /opengist + +CMD ["make", "watch"] + + +FROM base AS build + RUN make -FROM alpine:3.19 as run +FROM alpine:3.19 as prod RUN apk update && \ apk add --no-cache \ diff --git a/Makefile b/Makefile index e0ca23b..5430375 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all all_crosscompile install build_frontend build_backend build build_crosscompile build_docker watch_frontend watch_backend watch clean clean_docker check_changes go_mod fmt test +.PHONY: all all_crosscompile install build_frontend build_backend build build_crosscompile build_docker build_dev_docker run_dev_docker watch_frontend watch_backend watch clean clean_docker check_changes go_mod fmt test # Specify the name of your Go binary output BINARY_NAME := opengist @@ -31,16 +31,23 @@ build_docker: @echo "Building Docker image..." docker build -t $(BINARY_NAME):latest . +build_dev_docker: + @echo "Building Docker image..." + docker build -t $(BINARY_NAME)-dev:latest --target dev . + +run_dev_docker: + docker run -v .:/opengist -p 6157:6157 -p 16157:16157 $(BINARY_NAME)-dev:latest + watch_frontend: @echo "Building frontend assets..." - npx vite -c public/vite.config.js dev --port 16157 + npx vite -c public/vite.config.js dev --port 16157 --host watch_backend: @echo "Building Opengist binary..." OG_DEV=1 npx nodemon --watch '**/*' -e html,yml,go,js --signal SIGTERM --exec 'go run . --config config.yml' watch: - @bash ./scripts/watch.sh + @sh ./scripts/watch.sh clean: @echo "Cleaning up build artifacts..." diff --git a/README.md b/README.md index 364c098..b42c834 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Opengist is now running on port 6157, you can browse http://localhost:6157 ### From source -Requirements : [Git](https://git-scm.com/downloads) (2.28+), [Go](https://go.dev/doc/install) (1.21+), [Node.js](https://nodejs.org/en/download/) (16+) +Requirements: [Git](https://git-scm.com/downloads) (2.28+), [Go](https://go.dev/doc/install) (1.21+), [Node.js](https://nodejs.org/en/download/) (16+), [Make](https://linux.die.net/man/1/make) (optional, but easier) ```shell git clone https://github.com/thomiceli/opengist @@ -101,6 +101,9 @@ make Opengist is now running on port 6157, you can browse http://localhost:6157 +--- + +To create and run a development environment, see [run-development.md](/docs/contributing/run-development.md). ## Documentation diff --git a/docs/contributing/run-development.md b/docs/contributing/run-development.md new file mode 100644 index 0000000..405f797 --- /dev/null +++ b/docs/contributing/run-development.md @@ -0,0 +1,38 @@ +# Run Opengist in development mode + +## With Docker + +Assuming you have [Make](https://linux.die.net/man/1/make) installed, + +```shell +# Clone the repository +git clone git@github.com:thomiceli/opengist.git +cd opengist + +# Build the development image +make build_dev_docker +``` + +Now you can run the development image with the following command: + +```shell +make run_dev_docker +``` + +Opengist is now running on port 6157, you can browse http://localhost:6157 + +## As a binary + +Requirements: +* [Git](https://git-scm.com/downloads) (2.28+) +* [Go](https://go.dev/doc/install) (1.21+) +* [Node.js](https://nodejs.org/en/download/) (16+) +* [Make](https://linux.die.net/man/1/make) (optional, but easier) + +```shell +git clone git@github.com:thomiceli/opengist.git +cd opengist +make watch +``` + +Opengist is now running on port 6157, you can browse http://localhost:6157 diff --git a/docs/installation.md b/docs/installation.md index cfed154..c88f76f 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -58,10 +58,11 @@ chmod +x opengist ## From source -Requirements : +Requirements: * [Git](https://git-scm.com/downloads) (2.28+) * [Go](https://go.dev/doc/install) (1.21+) * [Node.js](https://nodejs.org/en/download/) (16+) +* [Make](https://linux.die.net/man/1/make) (optional, but easier) ```shell git clone https://github.com/thomiceli/opengist diff --git a/scripts/watch.sh b/scripts/watch.sh index 9dd5f87..ddf85c9 100755 --- a/scripts/watch.sh +++ b/scripts/watch.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh set -euo pipefail make watch_frontend &