Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: git push support #21

Merged
merged 22 commits into from
Feb 7, 2024
Merged
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ ARG CLI_TIMESTAMP="20200812001454"
RUN apt-get update && apt-get install -y --no-install-recommends \
jq \
u2f-host \
git \
openssh-client \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /tmp/aptible-cli
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
TAG?=$(shell git log --format="%H" -n 1)
PLATFORM?=linux/amd64

image:
docker buildx build \
--push \
--platform $(PLATFORM) \
-t quay.io/aptible/aptible-deploy-action:$(TAG) \
.
.PHONY: image
126 changes: 99 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,135 @@
# Github Action to deploy onto Aptible Deploy
This action helps you deploy Apps to [Aptible](https://www.aptible.com/).

This action deploys a Docker image to [Aptible](https://www.aptible.com/). To use this image, you should use another workflow step to publish your image to a Docker image registry (for example [Docker's](https://github.com/marketplace/actions/build-and-push-docker-images)).
There are two deployment strategies, both are supported in this action:

If you are using a private registry, you can optionally setup [Private Registry Authentication](https://deploy-docs.aptible.com/docs/private-registry-authentication) once ahead of time using the [Aptible CLI](https://deploy-docs.aptible.com/docs/cli). Otherwise, you can pass the credentials directly via the action.
- [Git Push](#git-push-deploy)
- [Direct Docker Image](#direct-docker-image-deploy)

```bash
aptible config:set \
--app "$APP_HANDLE" \
"APTIBLE_PRIVATE_REGISTRY_USERNAME=$USERNAME"
"APTIBLE_PRIVATE_REGISTRY_PASSWORD=$PASSWORD"
If you are just getting started at Aptible, the easiest deployment strategy is
[Git Push](#git-push-deploy).

# Git Push Deploy

[Read the docs on this strategy](https://www.aptible.com/docs/dockerfile-deploy).

## Inputs

The following inputs can be used as `step.with` keys

### Required input

- `username` - Aptible email login
- `password` - Aptible password login
- `app` - [Aptible App](https://www.aptible.com/docs/apps) handle
- `environment` -
[Aptible Environment](https://www.aptible.com/docs/environments) handle the
App is hosted within

### Optional input

- `config_variables` - [configuration variables to set](https://www.aptible.com/docs/set-configuration-variables)

> [!IMPORTANT]\
> We do **not** recommend setting `config_variables` inside our github action
> because those variables only need to be set once within Aptible for them to
> persist across deployments.
> [Learn more](https://www.aptible.com/docs/set-configuration-variables).

## Example using Git Push

Assumes you have set
[secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets)
(recommended).

```yaml
jobs:
deploy:
runs-on: ubuntu-latest

- name: Deploy to Aptible
uses: aptible/aptible-deploy-action@v2
with:
app: <app name>
joshraker marked this conversation as resolved.
Show resolved Hide resolved
environment: <environment name>
username: ${{ secrets.APTIBLE_USERNAME }}
password: ${{ secrets.APTIBLE_PASSWORD }}
```

# Direct Docker Image Deploy

[Read the docs on this strategy](https://www.aptible.com/docs/migrating-from-dockerfile-deploy).

To use this image, you should use another workflow step to publish your image to
a Docker image registry (for example
[Docker's](https://github.com/marketplace/actions/build-and-push-docker-images)).
Comment on lines +64 to +66
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future Improvement: It may be useful to provide an example of how to build and push to the repo's GitHub packages registry since my understanding is it should "just work" without any external setup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right, but can we look into this after this is deployed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's why I marked it as "Future Improvement".


If you are using a private registry, you can optionally setup
[Private Registry Authentication](https://deploy-docs.aptible.com/docs/private-registry-authentication)
once ahead of time using the
[Aptible CLI](https://deploy-docs.aptible.com/docs/cli). Otherwise, you can pass
the credentials directly via the action.

## Inputs

The following inputs can be used as `step.with` keys

### Required input

- `username` - passed to `aptible` CLI
- `password` - passed to `aptible` CLI
- `environment` - specifies App to be deployed
- `app` - specifies App to be deployed
- `docker_img` - the name of the image you’d like to deploy, including its repository and tag
- `type` - set to `docker`
- `username` - Aptible email login
- `password` - Aptible password login
- `environment` -
[Aptible Environment](https://www.aptible.com/docs/environments) handle the
App is hosted within
- `app` - [Aptible App](https://www.aptible.com/docs/apps) handle
- `docker_img` - the name of the image you'd like to deploy, including its
repository and tag

### Optional input

- `private_registry_username` - the username for the private registry to pull a docker image from
- `private_registry_password` - the password for the private registry to pull a docker image from
- `config_variables` - a space separated list of key=value pairs to set as config variables on the app during deployment
- `private_registry_username` - the username for the private image registry
- `private_registry_password` - the password for the private image registry
- `config_variables` - JSON string containing the
[configuration variables to set](https://www.aptible.com/docs/set-configuration-variables)

> [!IMPORTANT]\
> We do **not** recommend setting `config_variables` inside our github action
> because those variables only need to be set once within Aptible for them to
> persist across deployments.
> [Learn more](https://www.aptible.com/docs/set-configuration-variables).

## Outputs

- `status` - success/failure of the deploy

## Example github actions usage
## Example using Direct Docker Image Deploy

Assumes you have set [secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) (recommended).
Assumes you have set
[secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets)
(recommended).

```yaml
jobs:
deploy:
runs-on: ubuntu-latest

- name: Deploy to Aptible
uses: aptible/aptible-deploy-action@v1
uses: aptible/aptible-deploy-action@v2
with:
type: docker
app: <app name>
environment: <environment name>
username: ${{ secrets.APTIBLE_USERNAME }}
password: ${{ secrets.APTIBLE_PASSWORD }}
environment: <environment name>
app: <app name>
docker_img: <docker image name>
private_registry_username: ${{ secrets.DOCKERHUB_USERNAME }}
private_registry_password: ${{ secrets.DOCKERHUB_TOKEN }}
config_variables: KEY1=value1 KEY2=value2
config_variables: DEBUG=app:* FORCE_SSL=true
```

## Example with Container Build and Docker Hub
## Example using Container Build and Docker Hub

```yaml

env:
IMAGE_NAME: user/app:latest
APTIBLE_ENVIRONMENT: "my_environment"
Expand Down Expand Up @@ -92,12 +163,13 @@ jobs:
tags: ${{ env.IMAGE_NAME }}

- name: Deploy to Aptible
uses: aptible/aptible-deploy-action@v1
uses: aptible/aptible-deploy-action@v2
with:
type: docker
app: ${{ env.APTIBLE_APP }}
environment: ${{ env.APTIBLE_ENVIRONMENT }}
username: ${{ secrets.APTIBLE_USERNAME }}
password: ${{ secrets.APTIBLE_PASSWORD }}
environment: ${{ env.APTIBLE_ENVIRONMENT }}
app: ${{ env.APTIBLE_APP }}
docker_img: ${{ env.IMAGE_NAME }}
private_registry_username: ${{ secrets.DOCKERHUB_USERNAME }}
private_registry_password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand Down
24 changes: 16 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
# action.yml
name: 'Deploy to Aptible'
description: 'Deploy an app from a Dockerfile to Aptible'
description: 'Deploy an App to Aptible'
inputs:
username:
description: 'Aptible username'
required: True
password:
description: 'Aptible password'
required: True
environment:
description: 'Aptible environment'
environment:
description: 'Aptible environment handle'
required: True
app:
app:
description: 'App handle'
required: True
docker_img:
description: 'Docker image'
type:
description: 'Deploy strategy "git" or "deploy"'
required: True
default: 'git'
git_remote:
description: 'Aptible git remote domain'
required: False
default: elb-aptible-us-east-1-81550.aptible.in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use the internal domain and not either git.aptible.com or beta.aptible.com since those are much more likely to stay static?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my bad. Eric asked me what the hostname for primetime was and I didn't see a user domain on it so I just gave him the internal hostname. I overlooked the possibility of using a custom cert which would cause the endpoint to not have user domain. We should use git.aptible.com.

Copy link
Member

@UserNotFound UserNotFound Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use primetime.aptible.com, since it's a different service than Megatron (git.aptible.com).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or no certificate because it's using ssh not http 🤦

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

primetime.aptible.com ?

Is that what we should use for a git push?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use primetime.aptible.com, since it's a different service than Megatron (git.aptible.com).

Is that the right service to push to? Normally a user would push to beta.aptible.com or git.aptible.com which both point to megatron, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are interfacing directly with primetime in order to perform a git push using just an Aptible token. This makes this paradigm more visible to the outside world, something to think about.

Alex is right I glossed over that

docker_img:
description: 'Docker image'
required: False
private_registry_username:
description: 'Private Registry Username'
required: False
Expand All @@ -31,4 +38,5 @@ outputs:
description: "The Success/Failure of the action"
runs:
using: 'docker'
image: 'Dockerfile'
# image: 'Dockerfile'
image: docker://quay.io/aptible/aptible-deploy-action:v2
37 changes: 26 additions & 11 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ if [ -z "$INPUT_APP" ]; then
exit 1
fi

if [ -z "$INPUT_DOCKER_IMG" ]; then
echo "Aborting: docker_img is not set"
exit 1
fi

aptible login \
--email "$INPUT_USERNAME" \
--password "$INPUT_PASSWORD"
Expand All @@ -35,9 +30,29 @@ if ! APTIBLE_OUTPUT_FORMAT=json aptible apps | jq -e ".[] | select(.handle == \"
exit 1
fi

aptible deploy --environment "$INPUT_ENVIRONMENT" \
--app "$INPUT_APP" \
--docker-image "$INPUT_DOCKER_IMG" \
--private-registry-username "$INPUT_PRIVATE_REGISTRY_USERNAME" \
--private-registry-password "$INPUT_PRIVATE_REGISTRY_PASSWORD" \
${INPUT_CONFIG_VARIABLES}
if [ "$INPUT_TYPE" == "git" ]; then
export ACCESS_TOKEN=$(cat "$HOME/.aptible/tokens.json" | jq '.["https://auth.aptible.com"]' -r)
REMOTE_URL="root@$INPUT_GIT_REMOTE:$INPUT_ENVIRONMENT/$INPUT_APP.git"
git remote add aptible ${REMOTE_URL}
BRANCH="deploy-$(date "+%s")"
GIT_SSH_COMMAND="ssh -o SendEnv=ACCESS_TOKEN -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -p 43022" git push aptible "main:$BRANCH"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"main:$BRANCH" needs to change to whatever branch is currently checked out.


aptible deploy --environment "$INPUT_ENVIRONMENT" \
--app "$INPUT_APP" \
--git-commitish "$BRANCH" \
${INPUT_CONFIG_VARIABLES}
joshraker marked this conversation as resolved.
Show resolved Hide resolved
fi

if [ "$INPUT_TYPE" == "docker" ]; then
if [ -z "$INPUT_DOCKER_IMG" ]; then
echo "Aborting: docker_img is not set"
exit 1
fi

aptible deploy --environment "$INPUT_ENVIRONMENT" \
--app "$INPUT_APP" \
--docker-image "$INPUT_DOCKER_IMG" \
--private-registry-username "$INPUT_PRIVATE_REGISTRY_USERNAME" \
--private-registry-password "$INPUT_PRIVATE_REGISTRY_PASSWORD" \
${INPUT_CONFIG_VARIABLES}
fi