Skip to content

Commit f3a26db

Browse files
feat: Add Docker support (#804)
* feat: Add Docker support * feat: Update Dockerfile to enhance security headers and support SVG content * feat: Update Dockerfile to use PHP 8.3 and latest Composer version
1 parent 2009506 commit f3a26db

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

Dockerfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Use PHP 8.3 (8.4 not supported yet)
2+
FROM php:8.3-apache@sha256:6be4ef702b2dd05352f7e5fe14667696a4ad091c9d2ad9083becbee4300dc3b1
3+
4+
# Install system dependencies and PHP extensions in one layer
5+
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
git \
7+
unzip \
8+
libicu-dev \
9+
inkscape \
10+
fonts-dejavu-core \
11+
curl \
12+
&& docker-php-ext-configure intl \
13+
&& docker-php-ext-install intl \
14+
&& apt-get clean \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
# Install Composer
18+
COPY --from=composer/composer:latest-bin@sha256:c9bda63056674836406cacfbbdd8ef770fb4692ac419c967034225213c64e11b /composer /usr/bin/composer
19+
20+
# Set working directory
21+
WORKDIR /var/www/html
22+
23+
# Copy composer files and install dependencies
24+
COPY composer.json composer.lock ./
25+
COPY src/ ./src/
26+
RUN composer install --no-dev --optimize-autoloader --no-scripts
27+
28+
# Configure Apache to serve from src/ directory and pass environment variables
29+
RUN a2enmod rewrite headers && \
30+
echo 'ServerTokens Prod\n\
31+
ServerSignature Off\n\
32+
PassEnv TOKEN\n\
33+
<VirtualHost *:80>\n\
34+
ServerAdmin webmaster@localhost\n\
35+
DocumentRoot /var/www/html/src\n\
36+
<Directory /var/www/html/src>\n\
37+
Options -Indexes\n\
38+
AllowOverride None\n\
39+
Require all granted\n\
40+
Header always set Access-Control-Allow-Origin "*"\n\
41+
Header always set Content-Type "image/svg+xml" "expr=%{REQUEST_URI} =~ m#\\.svg$#i"\n\
42+
Header always set Content-Security-Policy "default-src 'none'; style-src 'unsafe-inline'; img-src data:;" "expr=%{REQUEST_URI} =~ m#\\.svg$#i"\n\
43+
Header always set Referrer-Policy "no-referrer-when-downgrade"\n\
44+
Header always set X-Content-Type-Options "nosniff"\n\
45+
</Directory>\n\
46+
ErrorLog ${APACHE_LOG_DIR}/error.log\n\
47+
CustomLog ${APACHE_LOG_DIR}/access.log combined\n\
48+
</VirtualHost>' > /etc/apache2/sites-available/000-default.conf
49+
50+
# Set secure permissions
51+
RUN chown -R www-data:www-data /var/www/html && \
52+
find /var/www/html -type d -exec chmod 755 {} \; && \
53+
find /var/www/html -type f -exec chmod 644 {} \;
54+
55+
# Health check
56+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
57+
CMD curl -f http://localhost/demo/ || exit 1
58+
59+
# Expose port
60+
EXPOSE 80
61+
62+
# Start Apache
63+
CMD ["apache2-foreground"]

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,39 @@ Heroku is another great option for hosting the files. All features are supported
253253

254254
You can transfer the files to any webserver using FTP or other means, then refer to [CONTRIBUTING.md](/CONTRIBUTING.md) for installation steps.
255255

256+
### 🐳 Docker
257+
258+
Docker is a great option for self-hosting with full control over your environment. All features are supported including PNG rendering with Inkscape. Expand the instructions below to learn how to deploy with Docker.
259+
260+
<details>
261+
<summary><b>Instructions for deploying with Docker</b></summary>
262+
263+
### Step-by-step instructions for deploying with Docker
264+
265+
1. Clone the repository:
266+
```bash
267+
git clone https://github.com/DenverCoder1/github-readme-streak-stats.git
268+
cd github-readme-streak-stats
269+
```
270+
271+
2. Visit https://github.com/settings/tokens/new?description=GitHub%20Readme%20Streak%20Stats to create a new Personal Access Token (no scopes required)
272+
273+
3. Scroll to the bottom and click "Generate token"
274+
275+
4. Build the Docker image:
276+
```bash
277+
docker build -t streak-stats .
278+
```
279+
280+
5. Run the container with your GitHub token:
281+
```bash
282+
docker run -d -p 8080:80 -e TOKEN=your_github_token_here streak-stats
283+
```
284+
285+
6. Visit http://localhost:8080 to access your self-hosted instance
286+
287+
</details>
288+
256289
[hspace]: https://user-images.githubusercontent.com/20955511/136058102-b79570bc-4912-4369-b664-064a0ada8588.png
257290
[verceldeploy]: https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FDenverCoder1%2Fgithub-readme-streak-stats%2Ftree%2Fvercel&env=TOKEN&envDescription=GitHub%20Personal%20Access%20Token%20(no%20scopes%20required)&envLink=https%3A%2F%2Fgithub.com%2Fsettings%2Ftokens%2Fnew%3Fdescription%3DGitHub%2520Readme%2520Streak%2520Stats&project-name=streak-stats&repository-name=github-readme-streak-stats
258291
[herokudeploy]: https://heroku.com/deploy?template=https://github.com/DenverCoder1/github-readme-streak-stats/tree/main

0 commit comments

Comments
 (0)