diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3981367d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,63 @@ +# Use PHP 8.3 (8.4 not supported yet) +FROM php:8.3-apache@sha256:6be4ef702b2dd05352f7e5fe14667696a4ad091c9d2ad9083becbee4300dc3b1 + +# Install system dependencies and PHP extensions in one layer +RUN apt-get update && apt-get install -y --no-install-recommends \ + git \ + unzip \ + libicu-dev \ + inkscape \ + fonts-dejavu-core \ + curl \ + && docker-php-ext-configure intl \ + && docker-php-ext-install intl \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Install Composer +COPY --from=composer/composer:latest-bin@sha256:c9bda63056674836406cacfbbdd8ef770fb4692ac419c967034225213c64e11b /composer /usr/bin/composer + +# Set working directory +WORKDIR /var/www/html + +# Copy composer files and install dependencies +COPY composer.json composer.lock ./ +COPY src/ ./src/ +RUN composer install --no-dev --optimize-autoloader --no-scripts + +# Configure Apache to serve from src/ directory and pass environment variables +RUN a2enmod rewrite headers && \ + echo 'ServerTokens Prod\n\ +ServerSignature Off\n\ +PassEnv TOKEN\n\ +\n\ + ServerAdmin webmaster@localhost\n\ + DocumentRoot /var/www/html/src\n\ + \n\ + Options -Indexes\n\ + AllowOverride None\n\ + Require all granted\n\ + Header always set Access-Control-Allow-Origin "*"\n\ + Header always set Content-Type "image/svg+xml" "expr=%{REQUEST_URI} =~ m#\\.svg$#i"\n\ + Header always set Content-Security-Policy "default-src 'none'; style-src 'unsafe-inline'; img-src data:;" "expr=%{REQUEST_URI} =~ m#\\.svg$#i"\n\ + Header always set Referrer-Policy "no-referrer-when-downgrade"\n\ + Header always set X-Content-Type-Options "nosniff"\n\ + \n\ + ErrorLog ${APACHE_LOG_DIR}/error.log\n\ + CustomLog ${APACHE_LOG_DIR}/access.log combined\n\ +' > /etc/apache2/sites-available/000-default.conf + +# Set secure permissions +RUN chown -R www-data:www-data /var/www/html && \ + find /var/www/html -type d -exec chmod 755 {} \; && \ + find /var/www/html -type f -exec chmod 644 {} \; + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost/demo/ || exit 1 + +# Expose port +EXPOSE 80 + +# Start Apache +CMD ["apache2-foreground"] \ No newline at end of file diff --git a/README.md b/README.md index dd45b6a9..3c1e6e05 100644 --- a/README.md +++ b/README.md @@ -253,6 +253,39 @@ Heroku is another great option for hosting the files. All features are supported You can transfer the files to any webserver using FTP or other means, then refer to [CONTRIBUTING.md](/CONTRIBUTING.md) for installation steps. +### 🐳 Docker + +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. + +
+ Instructions for deploying with Docker + +### Step-by-step instructions for deploying with Docker + +1. Clone the repository: + ```bash + git clone https://github.com/DenverCoder1/github-readme-streak-stats.git + cd github-readme-streak-stats + ``` + +2. Visit https://github.com/settings/tokens/new?description=GitHub%20Readme%20Streak%20Stats to create a new Personal Access Token (no scopes required) + +3. Scroll to the bottom and click "Generate token" + +4. Build the Docker image: + ```bash + docker build -t streak-stats . + ``` + +5. Run the container with your GitHub token: + ```bash + docker run -d -p 8080:80 -e TOKEN=your_github_token_here streak-stats + ``` + +6. Visit http://localhost:8080 to access your self-hosted instance + +
+ [hspace]: https://user-images.githubusercontent.com/20955511/136058102-b79570bc-4912-4369-b664-064a0ada8588.png [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 [herokudeploy]: https://heroku.com/deploy?template=https://github.com/DenverCoder1/github-readme-streak-stats/tree/main