A robust and automated solution for deploying static websites using GitHub Actions and NGINX. This repository provides a workflow to fetch static content from any GitHub repository, build a lean NGINX Docker image, and push it to the GitHub Container Registry (ghcr.io
).
- Automated Deployments: Trigger deployments manually or via API using
workflow_dispatch
. - Flexible Content Sourcing: Fetch static content from public or private repositories, with support for specific branches or tags.
- Custom NGINX Configuration: A pre-configured
nginx.conf
with commented-out options for advanced customization. - Dynamic Image Tagging: Automatically tags Docker images based on the Git reference of the source repository.
To get started, follow these steps:
-
Configure the Workflow: Edit the
env
section in.github/workflows/docker-build.yml
to specify your source repository details. -
Add Secrets: If your source repository is private, you must add a
SOURCE_DEPLOYMENT_KEY
secret to your repository settings. This should be a deploy key with read access to your source repository. -
Run the Workflow: Trigger the
Source Pull + Docker Build
workflow manually from the Actions tab in your GitHub repository. -
Deploy with Docker Compose: Use this repo's
docker-compose.yml
and.env
for deploying the container with minimal permissions / attack surface.
The deployment process is configured through environment variables in the .github/workflows/docker-build.yml
file.
Variable | Description | Default |
---|---|---|
DOCKER_REGISTRY |
The Docker registry to push the image to. | ghcr.io |
SOURCE_REPOSITORY |
The GitHub repository to fetch static content from (e.g., owner/repo ). |
owner/source-repo |
SOURCE_REF |
The branch or tag to check out from the source repository. | main |
SOURCE_DIRECTORY |
The directory within the source repository that contains the static content. | public |
IMAGE_NAME |
The name of the Docker image to build. | my-nginx-image |
Tip
For private repositories, ensure that the SOURCE_DEPLOYMENT_KEY
secret is an SSH private key with read access to the source repository.
To pull images from the GitHub Container Registry (ghcr.io
) outside of GitHub Actions (e.g., on your local machine or another server), you need to authenticate using a GitHub Personal Access Token (PAT) with the read:packages
scope.
-
Create a Personal Access Token
- Go to GitHub Settings > Developer settings > Personal access tokens.
- Generate a new token with at least the
read:packages
scope.
-
Login to the registry
Use Docker to authenticate.
docker login ghcr.io -u YOUR_GITHUB_USERNAME
Copy the docker-compose.yml
and .env
file to your system.
-
Configure environment variables Edit the
.env
file and set:IMG
to your container image (e.g.,ghcr.io/USER/IMG-NAME:REF
)IMG-PORT
to the local port you want to use (e.g.,5050
)
-
Start the service
docker compose up -d
-
Access the service Visit http://127.0.0.1:5050 (replace
5050
with your chosen port). -
Stop the service
docker compose down
This project is configured to use the minimum required permissions. All sensitive information, such as deployment keys, should be stored as encrypted secrets in your GitHub repository.
Contributions are welcome! Please feel free to submit a pull request or open an issue to discuss proposed changes.
This project is licensed under the MIT License. See the LICENSE file for details.