GitHub Deployer is a Docker image that can be used to interact with the GitHub Deployments API.
Background and full article: https://zentered.co/articles/preview-builds-with-cloud-run/
This code is meant to be used in a CI/CD pipeline to interact with the GitHub Deployments API. You need to have or create a GitHub App and build the Docker image yourself.
GitHub Deployer uses a GitHub App to authenticate with GitHub. You can create your own GitHub App in the Developer Settings of your GitHub account.
The following permissions are needed:
deployments
pull_requests
contents
Create & download the private key and run:
base64 -i your.private-key.pem
This is the value you need to set for the GH_APP_PRIVATE_KEY
environment.
An example to build & push the image to Google Cloud Artifact Registry. The static GitHub variables are "baked in" the image to simplify the calls in the CI.
docker buildx build --platform linux/amd64 . -t us-central1-docker.pkg.dev/[your-project]/docker/gh-deployer \
--build-arg GH_APP_ID=111111 \
--build-arg GH_APP_INSTALLATION_ID=111111 \
--build-arg GH_APP_PRIVATE_KEY=111111 \
--build-arg GH_OWNER=zentered
docker push us-central1-docker.pkg.dev/[your-project]/docker/gh-deployer
Name | Description | Required | Default |
---|---|---|---|
GH_APP_ID | GitHub App ID | Yes | |
GH_APP_INSTALLATION_ID | GitHub App Installation ID | Yes | |
GH_APP_PRIVATE_KEY | GitHub App Key | Yes | |
GH_OWNER | GitHub Owner (ie zentered ) |
Yes |
Name | Description | Required | Default |
---|---|---|---|
REPO_NAME | GitHub Repo (ie gh-deployer ) |
Yes | |
REF | GitHub Ref (this should be the SHA in your deployment step) | Yes | |
ENVIRONMENT | Environment (ie production ) |
Yes | |
TRANSIENT_ENVIRONMENT | Transient Environment (is the deployment temporary [true] or permanent [false]) | No | false |
DESCRIPTION | Description of the deployment | No |
The first step is to create a new deployment for a given sha or branch with the
create
command. This will return a deployment ID that you can store in the
workspace of your CI. Afterwards you create "Deployment Status" events with the
deployment URL:
- 'error'
- 'failure'
- 'pending'
- 'in_progress'
- 'queued'
- 'success'
docker run \
-e REF=3b2fae5 \
-e ENVIRONMENT=production \
-e TRANSIENT_ENVIRONMENT=false \
-e DESCRIPTION="Deploying to production" \
zentered/gh-deployer
create
docker run \
-e REF=3b2fae5 \
-e ENVIRONMENT=production \
-e TRANSIENT_ENVIRONMENT=false \
-e DESCRIPTION="Deploying to production" \
zentered/gh-deployer
in_progress
111111
docker run \
-e REF=3b2fae5 \
-e ENVIRONMENT=production \
-e TRANSIENT_ENVIRONMENT=false \
-e DESCRIPTION="Deploying to production" \
zentered/gh-deployer
success
111111
https://zentered.co
- Create a new Docker repository in Artifact Registry
- Build, tag & push to the repository
- Use the image in Cloud Build