This project provides a self-hosted CI/CD environment using Docker, integrating a GitHub Actions runner, a private Docker registry, and a PyPI server.
- Self-hosted GitHub Actions Runner: Automated operations within your repository.
- Docker Registry: Private registry for Docker images.
- PyPI Server: Hosts Python packages internally.
- Nginx: Routes traffic to Docker Registry and PyPI server.
Retrieve the token:
- Go to your GitHub repository settings.
- Navigate to
Actions
>Runners
>New self-hosted runner
. - Copy the token displayed during setup.
Adjust the docker-compose.yml
to fit your repository details and runner configuration:
services:
self_hosted_github_actions:
build:
args:
repo_url: <YOUR_REPO_URL>
runner_name: <OPTIONAL_RUNNER_NAME>
secrets:
github_actions_token:
file: <PATH_TO_GITHUB_ACTIONS_TOKEN>
-
Create a
.htpasswd
file for the Docker Registry.- Run this command and follow the instructions to create a password
htpasswd -c .htpasswd <USERNAME>
- Move the
.htpasswd
file to thedocker-registry
directory.
mv .htpasswd docker-registry/
-
Create a
.htpasswd
file for the PyPI server.- Run this command and follow the instructions to create a password
htpasswd -c .htpasswd <USERNAME>
- Move the
.htpasswd
file to thepypiserver
directory.
mv .htpasswd pypi-server/
To launch all services:
docker-compose up -d
Now, you have a self-hosted CI/CD environment with a GitHub Actions runner, a private Docker registry, and a PyPI server. Refer to python-template for an example repository that uses this CI/CD environment.
With Nginx running, you can access the PyPI server and the Docker Registry from your host machine by their service names, without needing to expose their ports. For docker registry, you have to specify default port 80. Otherwise docker commands will not work. You do not need to manage ports or IP addresses manually.
To upload a package to the PyPI server:
twine upload --repository-url http://pypi-server/ dist/* --username <USERNAME> --password <PASSWORD>
To install a package from the PyPI server:
pip install --extra-index-url http://pypi-server/ --trusted-host pypi-server <PACKAGE_NAME>
To push an image to the Docker Registry:
docker tag <IMAGE_NAME> docker-registry:80/<IMAGE_NAME>
docker login docker-registry:80 -u <USERNAME> -p <PASSWORD>
docker push docker-registry:80/<IMAGE_NAME>
To pull an image from the Docker Registry:
docker login docker-registry:80 -u <USERNAME> -p <PASSWORD>
docker pull docker-registry:80/<IMAGE_NAME>
To stop all services:
docker-compose down
This project is licensed under the MIT License - see the LICENSE.txt
file for details.