Skip to content

Commit

Permalink
Create docker dev env (thomiceli#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomiceli committed Apr 2, 2024
1 parent 86ad88f commit 3179762
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 13 deletions.
34 changes: 27 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 \
Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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..."
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Opengist is now running on port 6157, you can browse http:https://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
Expand All @@ -101,6 +101,9 @@ make

Opengist is now running on port 6157, you can browse http:https://localhost:6157

---

To create and run a development environment, see [run-development.md](/docs/contributing/run-development.md).

## Documentation

Expand Down
38 changes: 38 additions & 0 deletions docs/contributing/run-development.md
Original file line number Diff line number Diff line change
@@ -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 [email protected]: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:https://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 [email protected]:thomiceli/opengist.git
cd opengist
make watch
```

Opengist is now running on port 6157, you can browse http:https://localhost:6157
3 changes: 2 additions & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/watch.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
set -euo pipefail

make watch_frontend &
Expand Down

0 comments on commit 3179762

Please sign in to comment.