Skip to content

Commit 08f3ab3

Browse files
authored
Setup docker and make (#58)
1 parent 0c78ca0 commit 08f3ab3

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.git
2+
.github
3+
vendor
4+
node_modules
5+
docs
6+
.dockerignore
7+
Dockerfile
8+
docker-compose.yml
9+
.gitignore
10+
.gitattributes
11+
README.md

Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM php:8.3-cli
2+
3+
# Install system dependencies
4+
RUN apt-get update && apt-get install -y \
5+
git \
6+
unzip \
7+
libzip-dev \
8+
libxml2-dev \
9+
libonig-dev \
10+
zip \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# Install PHP extensions required by the project
14+
RUN docker-php-ext-install zip
15+
RUN docker-php-ext-install dom
16+
RUN docker-php-ext-install simplexml
17+
RUN docker-php-ext-install mbstring
18+
RUN docker-php-ext-configure pcntl --enable-pcntl && docker-php-ext-install pcntl
19+
20+
# Install Composer
21+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
22+
23+
# Set working directory
24+
WORKDIR /var/www/html
25+
26+
# Copy project files
27+
COPY . .
28+
29+
# Set up entrypoint
30+
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
31+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
32+
ENTRYPOINT ["docker-entrypoint.sh"]
33+
34+
# Install dependencies by default (can be overridden)
35+
CMD ["composer", "install"]

Makefile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.PHONY: build install generate build-site serve test lint fix-lint coverage help
2+
3+
IMAGE_NAME = mergephp-website
4+
CONTAINER_NAME = mergephp-website-container
5+
HOST_PORT = 8000
6+
CONTAINER_PORT = 8000
7+
8+
# Default target
9+
help:
10+
@echo "Available commands:"
11+
@echo " make build - Build the Docker image"
12+
@echo " make install - Install Composer dependencies"
13+
@echo " make generate - Generate a new meetup"
14+
@echo " make build-site - Build the static site"
15+
@echo " make serve - Serve the site on localhost:$(HOST_PORT)"
16+
@echo " make test - Run PHPUnit tests"
17+
@echo " make lint - Check code style"
18+
@echo " make fix-lint - Fix lint errors automatically"
19+
@echo " make coverage - Generate code coverage report"
20+
@echo " make bash - Open a bash shell in the container"
21+
22+
# Build the Docker image
23+
build:
24+
docker build -t $(IMAGE_NAME) .
25+
26+
# Install dependencies
27+
install:
28+
docker run --rm -v $(PWD):/var/www/html $(IMAGE_NAME) composer install
29+
30+
# Generate a new meetup
31+
generate: build
32+
docker run --rm -it -v $(PWD):/var/www/html $(IMAGE_NAME) composer generate
33+
34+
# Build the static site
35+
build-site: build
36+
docker run --rm -v $(PWD):/var/www/html $(IMAGE_NAME) composer build
37+
38+
# Serve the site
39+
serve: build
40+
docker run --rm -p $(HOST_PORT):$(CONTAINER_PORT) -v $(PWD):/var/www/html --name $(CONTAINER_NAME) $(IMAGE_NAME) php -S 0.0.0.0:$(CONTAINER_PORT) -t docs/
41+
42+
# Run tests
43+
test: build
44+
docker run --rm -v $(PWD):/var/www/html $(IMAGE_NAME) composer test
45+
46+
# Run lint check
47+
lint: build
48+
docker run --rm -v $(PWD):/var/www/html $(IMAGE_NAME) composer lint
49+
50+
# Fix lint errors
51+
fix-lint: build
52+
docker run --rm -v $(PWD):/var/www/html $(IMAGE_NAME) composer fix-lint-errors
53+
54+
# Generate code coverage
55+
coverage: build
56+
docker run --rm -v $(PWD):/var/www/html $(IMAGE_NAME) composer coverage
57+
58+
# Open a bash shell in the container
59+
bash: build
60+
docker run --rm -it -v $(PWD):/var/www/html $(IMAGE_NAME) bash

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
container_name: mergephp-website
9+
volumes:
10+
- .:/var/www/html
11+
ports:
12+
- "8000:8000"
13+
command: php -S 0.0.0.0:8000 -t docs/

docker-entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Execute the command passed as arguments
5+
exec "$@"

0 commit comments

Comments
 (0)