Skip to content
Closed
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
8 changes: 5 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"name": "listmonk",
"dockerComposeFile": "../dev/docker-compose.yml",
"service": "backend",
"service": "devcontainer",
"workspaceFolder": "/app",
"forwardPorts": [9000],
"postStartCommand": "make dist && ./listmonk --install --idempotent --yes --config dev/config.toml"
"runServices": ["adminer", "mailhog", "db", "backend", "front"],
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
}
}
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ release-dry:
release:
goreleaser release --parallelism 1 --clean

# App services for `make dev-docker` (excludes the devcontainer workspace).
DEV_DOCKER_SERVICES = adminer mailhog db backend front

# Build local docker images for development.
.PHONY: build-dev-docker
build-dev-docker: build ## Build docker containers for the entire suite (Front/Core/PG).
Expand All @@ -129,13 +132,20 @@ build-dev-docker: build ## Build docker containers for the entire suite (Front/C
.PHONY: dev-docker
dev-docker: build-dev-docker ## Build and spawns docker containers for the entire suite (Front/Core/PG).
cd dev; \
docker compose up
docker compose up $(DEV_DOCKER_SERVICES)

# Run the backend in docker-dev mode. The frontend assets in dev mode are loaded from disk from frontend/dist.
.PHONY: run-backend-docker
run-backend-docker:
CGO_ENABLED=0 go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}' -X 'main.frontendDir=frontend/dist'" ./cmd --config=dev/config.toml

# Build assets and install the DB schema for the docker dev suite.
.PHONY: init-docker
init-docker:
@test -d frontend/dist || $(MAKE) build-frontend
@test -f $(BIN) || $(MAKE) build
./listmonk --install --idempotent --yes --config dev/config.toml

# Tear down the complete local development docker suite.
.PHONY: rm-dev-docker
rm-dev-docker: build ## Delete the docker containers including DB volumes.
Expand All @@ -144,6 +154,6 @@ rm-dev-docker: build ## Delete the docker containers including DB volumes.

# Setup the db for local dev docker suite.
.PHONY: init-dev-docker
init-dev-docker: build-dev-docker ## Delete the docker containers including DB volumes.
init-dev-docker: build-dev-docker ## Build assets and install the DB schema in docker.
cd dev; \
docker compose run --rm backend sh -c "make dist && ./listmonk --install --idempotent --yes --config dev/config.toml"
docker compose run --rm init
38 changes: 37 additions & 1 deletion dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ services:
source: listmonk-dev-db
target: /var/lib/postgresql/data

init:
build:
context: ../
dockerfile: dev/app.Dockerfile
command: ["make", "init-docker"]
depends_on:
db:
condition: service_started
volumes:
- ../:/app
- ${GOPATH:-${HOME}/go}/pkg/mod/cache:/go/pkg/mod/cache
networks:
- listmonk-dev
restart: "no"

front:
build:
context: ../
Expand All @@ -57,13 +72,34 @@ services:
ports:
- "9000:9000"
depends_on:
- db
db:
condition: service_started
init:
condition: service_completed_successfully
volumes:
- ../:/app
- ${GOPATH:-${HOME}/go}/pkg/mod/cache:/go/pkg/mod/cache
networks:
- listmonk-dev

# Workspace container for VS Code / Cursor devcontainers. Omitted from
# `make dev-docker`; the editor starts this service when reopening in container.
devcontainer:
image: dev-devcontainer
build:
context: ../
dockerfile: dev/app.Dockerfile
command: ["sleep", "infinity"]
volumes:
- ../:/app
- ${GOPATH:-${HOME}/go}/pkg/mod/cache:/go/pkg/mod/cache
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
db:
condition: service_started
networks:
- listmonk-dev

volumes:
listmonk-dev-db:

Expand Down
3 changes: 1 addition & 2 deletions docs/docs/content/developer-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ After setting up the dev environment, you can visit `http://localhost:8080`.

2. Inside containers (Using Makefile)

- Run `make init-dev-docker` to setup container for db.
- Run `make dev-docker` to setup docker container suite.
- Run `make dev-docker` to build and start the docker container suite.
- Run `make rm-dev-docker` to clean up docker container suite.

3. Inside containers (Using devcontainer)
Expand Down
Loading