Skip to content

Commit 3568496

Browse files
authored
Merge pull request #5 from simonprydden/4-add-local-development-setup
add local development environment
2 parents dda4e89 + 8d3b857 commit 3568496

File tree

4 files changed

+141
-1
lines changed

4 files changed

+141
-1
lines changed

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,61 @@
1-
# simonprydden.github.io
1+
# Personal Handbook
2+
3+
## About
4+
5+
This repository contains the documentation for my personal website, built using [Docusaurus](https://docusaurus.io/).
6+
The site is deployed via GitHub Pages and can be accessed at [simonprydden.github.io](https://simonprydden.github.io/).
7+
8+
## Features
9+
- **Built with Docusaurus**: A modern, React-based static site generator.
10+
- **GitHub Pages Deployment**: Automatic deployment after changes are merged into the repository.
11+
- **Customizable Content**: Easily add or edit `.md` files for documentation and blogs.
12+
13+
---
14+
15+
## Installation
16+
17+
### Prerequisites
18+
19+
Before starting, ensure the following tools are installed:
20+
- **Docker Compose**: Follow the [official installation guide](https://docs.docker.com/compose/install/).
21+
- **Docker Engine**: Install it using the [official installation guide](https://docs.docker.com/engine/install/).
22+
23+
### Getting Started
24+
25+
1. Clone the repository:
26+
```bash
27+
git clone https://github.com/simonprydden/simonprydden.github.io.git
28+
```
29+
2. Navigate to the project directory:
30+
```bash
31+
cd simonprydden.github.io
32+
```
33+
34+
---
35+
36+
## Local Development
37+
38+
To preview and develop the site locally:
39+
40+
1. Start the development server:
41+
```bash
42+
make start
43+
```
44+
This command will spin up a local Docusaurus server, typically accessible at `http://localhost:3000`.
45+
46+
2. Add or edit content:
47+
- Add documentation in the `docs` directory.
48+
- Write blog posts in the `blog` directory.
49+
50+
3. Preview your changes in real time.
51+
52+
---
53+
54+
## Deployment
55+
56+
To publish your changes:
57+
58+
1. Test your changes locally to ensure everything works as expected.
59+
2. Open a Pull Request (PR) to submit your updates for review.
60+
3. After the PR is reviewed and merged, your changes will be automatically deployed to [simonprydden.github.io](https://simonprydden.github.io/).
61+

docker-compose.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: "docusaurus"
2+
services:
3+
dev:
4+
build:
5+
context: .
6+
dockerfile: docker/dockerfile
7+
target: dev
8+
ports:
9+
- "3000:3000"
10+
volumes:
11+
- ./website:/opt/docusaurus
12+
environment:
13+
- NODE_ENV=development

docker/dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Stage 1: Base image.
2+
FROM node:lts AS base
3+
4+
## Disable colour output from yarn to make logs easier to read.
5+
ENV FORCE_COLOR=0
6+
RUN corepack enable
7+
WORKDIR /opt/docusaurus
8+
9+
# Stage 2a: Development mode.
10+
FROM base AS dev
11+
WORKDIR /opt/docusaurus
12+
EXPOSE 3000
13+
## Run the development server.
14+
CMD [ -d "node_modules" ] && npm run start -- --host 0.0.0.0 --poll 1000 || npm install && npm run start -- --host 0.0.0.0 --poll 1000
15+
16+
# Stage 2b: Production build mode.
17+
FROM base AS prod
18+
WORKDIR /opt/docusaurus
19+
## Copy over the source code.
20+
COPY ./website /opt/docusaurus/
21+
RUN npm ci
22+
RUN npm run build
23+
24+
# Stage 3a: Serve with `docusaurus serve`.
25+
FROM prod AS serve
26+
EXPOSE 3000
27+
## Run the production server.
28+
CMD ["npm", "run", "serve", "--", "--host", "0.0.0.0", "--no-open"]
29+
30+
# Stage 3b: Serve with Caddy.
31+
FROM caddy:2-alpine AS caddy
32+
## Copy the Caddyfile.
33+
COPY --from=prod /opt/docusaurus/Caddyfile /etc/caddy/Caddyfile
34+
## Copy the Docusaurus build output.
35+
COPY --from=prod /opt/docusaurus/build /var/docusaurus

makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Targets
2+
.PHONY: help start stop clean
3+
4+
SHELL := /bin/bash
5+
6+
help:
7+
@echo "Usage: make <target>"
8+
@echo ""
9+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$|(^#--)' $(MAKEFILE_LIST) \
10+
| grep -v '^\(include\|[A-Z_]\+\s*=\)' \
11+
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m %-43s\033[0m %s\n", $$1, $$2}' \
12+
| sed -e 's/\[32m #-- /[33m/'
13+
14+
#-- Docker
15+
start: ## Start the docusaurus services
16+
@echo "Starting docusaurus services..."
17+
docker compose up -d
18+
19+
stop: ## Stop the docusaurus services
20+
@echo "Stopping docusaurus services..."
21+
docker compose stop
22+
23+
clean: ## Remove all Docker containers, networks, and volumes
24+
@echo "Cleaning up docusaurus resources..."
25+
docker compose down -v --remove-orphans
26+
27+
#-- Utilities
28+
open: ## Open the Docusaurus site in the default web browser
29+
@echo "Opening Docusaurus site..."
30+
xdg-open http://localhost:3000 2>/dev/null || \
31+
open http://localhost:3000 2>/dev/null || \
32+
start http://localhost:3000

0 commit comments

Comments
 (0)