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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
dist
vendor/
bin/
podman/**
!podman/env.example
.env
136 changes: 136 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ else
endif
endif

## Alias for server target - builds the server component.
.PHONY: build
build: server

## Ensures NPM dependencies are installed without having to run this all the time.
webapp/node_modules: $(wildcard webapp/package.json)
ifneq ($(HAS_WEBAPP),)
Expand Down Expand Up @@ -279,6 +283,24 @@ ifneq ($(HAS_WEBAPP),)
endif
rm -fr build/bin/

## Formats Go and Markdown code.
.PHONY: format
format:
@echo Formatting code...
ifneq ($(HAS_SERVER),)
@echo Formatting Go files...
$(GO) fmt ./...
endif
@echo Formatting Markdown files...
@if command -v prettier > /dev/null 2>&1; then \
prettier --write "**/*.md"; \
elif command -v npx > /dev/null 2>&1; then \
npx --yes prettier --write "**/*.md"; \
else \
echo "Warning: prettier not found. Install it with 'npm install -g prettier' to format Markdown files."; \
fi
@echo Formatting complete.

.PHONY: logs
logs:
./build/bin/pluginctl logs $(PLUGIN_ID)
Expand All @@ -287,6 +309,120 @@ logs:
logs-watch:
./build/bin/pluginctl logs-watch $(PLUGIN_ID)

# Development environment management with Podman Compose
PODMAN_COMPOSE_FILE ?= podman-compose.yml
PODMAN_COMPOSE := podman-compose -f $(PODMAN_COMPOSE_FILE)

## Sets up the required directories for Podman development stack.
.PHONY: dev-setup
dev-setup:
@./build/scripts/dev-preflight-check.sh

## Starts the Podman Compose development stack.
.PHONY: dev-up
dev-up: dev-setup
@echo "Starting development environment..."
$(PODMAN_COMPOSE) up -d
@echo "Waiting for Mattermost to be ready..."
@timeout 60 bash -c 'until $$(curl -s http://localhost:8065/api/v4/system/ping > /dev/null 2>&1); do sleep 2; done' || echo "Mattermost is starting. Access at http://localhost:8065"
@echo "Creating admin account if it doesn't exist..."
@$(MAKE) dev-create-admin || echo "Admin account already exists or creation failed"

## Stops the Podman Compose development stack and removes volumes.
## This ensures a clean state for the next dev-up.
.PHONY: dev-down
dev-down:
@echo "Stopping development environment and removing volumes..."
$(PODMAN_COMPOSE) down -v

## Creates the admin account if it doesn't exist.
## Uses credentials from podman-compose.yml (admin/admin123/admin@example.com)
## Also creates a default team and adds the admin user to it.
.PHONY: dev-create-admin
dev-create-admin:
@./build/scripts/dev-create-admin.sh

## Alias for dev-up
.PHONY: dev-start
dev-start: dev-up

## Alias for dev-down
.PHONY: dev-stop
dev-stop: dev-down

## Restarts the Podman Compose development stack.
.PHONY: dev-restart
dev-restart: dev-down dev-up

## Removes containers, volumes, and data for a clean start.
.PHONY: dev-clean
dev-clean:
@echo "Cleaning development environment (removing containers, volumes, and data)..."
$(PODMAN_COMPOSE) down -v
build/scripts/dir-cleanup.sh podman/data/ podman/config/
@echo "Development environment cleaned. Run 'make dev-up' to start fresh."

## Views Mattermost server logs.
.PHONY: dev-logs
dev-logs:
$(PODMAN_COMPOSE) logs mattermost

## Tails Mattermost server logs in real-time.
.PHONY: dev-logs-watch
dev-logs-watch:
$(PODMAN_COMPOSE) logs -f mattermost

## Builds and deploys the plugin to the Podman development stack.
.PHONY: dev-deploy
dev-deploy: dist
@PLUGIN_ID=$(PLUGIN_ID) BUNDLE_NAME=dist/$(BUNDLE_NAME) ./build/scripts/dev-deploy.sh

## Opens a shell in the Mattermost container.
.PHONY: dev-shell
dev-shell:
$(PODMAN_COMPOSE) exec mattermost /bin/sh

## Shows status of Podman Compose services.
.PHONY: dev-status
dev-status:
$(PODMAN_COMPOSE) ps

## Enables the plugin in the development environment.
.PHONY: dev-enable
dev-enable:
@./build/scripts/dev-pluginctl.sh enable

## Disables the plugin in the development environment.
.PHONY: dev-disable
dev-disable:
@./build/scripts/dev-pluginctl.sh disable

## Resets the plugin in the development environment (disables and re-enables).
.PHONY: dev-reset
dev-reset:
@./build/scripts/dev-pluginctl.sh reset

## Views plugin logs in the development environment.
.PHONY: dev-plugin-logs
dev-plugin-logs:
@./build/scripts/dev-pluginctl.sh logs

## Tails plugin logs in the development environment.
.PHONY: dev-plugin-logs-watch
dev-plugin-logs-watch:
@./build/scripts/dev-pluginctl.sh logs-watch

## Pings the Mattermost healthcheck endpoint to verify server is responding.
.PHONY: dev-check-ping
dev-check-ping:
@echo "Checking Mattermost healthcheck endpoint..."
@if $(CURL) -f -s http://localhost:8065/api/v4/system/ping > /dev/null 2>&1; then \
echo "✓ Mattermost is responding (http://localhost:8065/api/v4/system/ping)"; \
else \
echo "✗ Mattermost is not responding. Is it running? (Try 'make dev-up')"; \
exit 1; \
fi

# Help documentation à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@cat Makefile build/*.mk | grep -v '\.PHONY' | grep -v '\help:' | grep -B1 -E '^[a-zA-Z0-9_.-]+:.*' | sed -e "s/:.*//" | sed -e "s/^## //" | grep -v '\-\-' | sed '1!G;h;$$!d' | awk 'NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort
73 changes: 73 additions & 0 deletions build/scripts/dev-check-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
#
# dev-check-container.sh - Verify Mattermost development container status
#
# PURPOSE:
# This script ensures the Mattermost development container is running before
# other scripts attempt to interact with it. It also loads environment variables
# from the podman/.env file to make credentials and configuration available to
# calling scripts.
#
# USAGE:
# This script is typically sourced by other development scripts:
# source build/scripts/dev-check-container.sh
#
# ENVIRONMENT:
# PODMAN_COMPOSE_FILE - Path to podman-compose file (default: podman-compose.yml)
#
# EXIT CODES:
# 0 - Container is running and ready
# 1 - Container is not running or dependencies missing
#
# NOTES:
# - This script changes to PROJECT_ROOT directory
# - Environment variables from podman/.env are exported to calling shell
# - Use 'set -a' pattern to automatically export variables when sourcing .env
#

set -euo pipefail

# Determine script and project directories
# Only set as readonly if not already defined (allows sourcing by other scripts)
if [[ -z "${SCRIPT_DIR:-}" ]]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly SCRIPT_DIR
fi

if [[ -z "${PROJECT_ROOT:-}" ]]; then
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
readonly PROJECT_ROOT
fi

if [[ -z "${PODMAN_COMPOSE_FILE:-}" ]]; then
PODMAN_COMPOSE_FILE="podman-compose.yml"
readonly PODMAN_COMPOSE_FILE
fi

# Check for required tools
if ! command -v podman-compose &>/dev/null; then
echo "Error: podman-compose is not installed or not in PATH" >&2
echo "Install it with: pip install podman-compose" >&2
exit 1
fi

# Change to project root for consistent behavior
cd "${PROJECT_ROOT}"

# Verify Mattermost container is running
# We check for "Up" or "starting" status in the podman-compose output
if ! podman-compose -f "${PODMAN_COMPOSE_FILE}" ps | grep -qE "mattermost.*(Up|starting)"; then
echo "Error: Mattermost container is not running" >&2
echo "Start it with: make dev-up" >&2
exit 1
fi

# Load environment variables from podman/.env if present
# Using 'set -a' causes all variables to be exported automatically
readonly ENV_FILE="podman/.env"
if [[ -f "${ENV_FILE}" ]]; then
set -a
# shellcheck source=/dev/null
source "${ENV_FILE}"
set +a
fi
Loading