There are no doubts GitHub Packages Repository (GPR) provides an easy and straightforward way to publish Maven artifacts within GitHub ecosystem.
However, GitHub doesn't allow anonymous read which makes consuming those packages somewhat awkward and requires user to provide explicit Personal Access Token (PAT).
This project comes to help as it allows to proxy all GPR requests and resolve dependencies without the need to create and provide PAT.
Follow the instructions
to create a personal access token
and only set read:packages
as a required permission.
Proxy will rely on this token to get access and read packages deployed under your profile.
The same token can be used to access and read public packages from ANY other from GitHub Package Repositories.
The following command will start proxy at your host machine on port 8080 by default
export GITHUB_USER=<YOUR_USERNAME>
export GITHUB_TOKEN=<ABOVE_TOKEN>
./gradlew run
Edit your build.gradle
and provide url to your local proxy
maven {
url 'http://0.0.0.0:8080'
allowInsecureProtocol true
}
You can deploy this proxy to any Cloud Provider / Server / VPS able to run java runtime.
Run following command that will create executable fatJar that contains all the dependencies
./gradlew build
The easiest way to build a docker image is to use Ktor's bundled jib tool
Just run the following command to build an image to a Docker daemon
./gradlew jibDockerBuild
or to your specific container registry (dockerHub, GCR, ECR, etc)
./gradlew jib --image=<IMAGE_NAME>
you can then run the container or deploy it to whatever service that is able to run Docker containers
docker run --env GITHUB_USER=user --env GITHUB_TOKEN=token -p 8080:8080 -d ktor-github-package-registry-proxy
The easiest and free option to get your proxy up and running is to deploy to fly.io as they have a free tier which is enough for this kind of service.
- Delete
fly.toml
in the root of this project. - Install
flyctl
command line tools for your platform. - Run following commands and follow onscreen instructions
fly auth login
fly launch --no-deploy
fly deploy
don't forget to change your compute instance to meet free tier allowance.
For more details refer to official fly.io documentation.
That's it! Now you can use fly's app url to reference to your GPR proxy.
Enjoy!