https://github.com/analythium/app-platform-gh-actions
Integrate DigitalOcean App Platform with GitHub Actions in a true CICD fashion
https://github.com/analythium/app-platform-gh-actions
Last synced: 4 months ago
JSON representation
Integrate DigitalOcean App Platform with GitHub Actions in a true CICD fashion
- Host: GitHub
- URL: https://github.com/analythium/app-platform-gh-actions
- Owner: analythium
- License: mit
- Created: 2021-09-25T19:41:39.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-02T04:49:38.000Z (over 3 years ago)
- Last Synced: 2024-08-13T07:13:23.466Z (8 months ago)
- Language: R
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - analythium/app-platform-gh-actions - Integrate DigitalOcean App Platform with GitHub Actions in a true CICD fashion (R)
README
# app-platform-gh-actions
> Integrate DigitalOcean App Platform with GitHub Actions in a true CICD fashion
https://docs.digitalocean.com/reference/doctl/reference/auth/init/
### Create an app
Build the image locally, test, then and push to Docker Hub:
```bash
## export few variables
export REGISTRY="analythium"
export IMAGE_NAME="github-action-test"
export GITHUB_SHA="latest"## build the image
docker build -t $REGISTRY/$IMAGE_NAME:$GITHUB_SHA .## run and test
docker run -p 8080:8080 $REGISTRY/$IMAGE_NAME:$GITHUB_SHA## push the image
docker push $REGISTRY/$IMAGE_NAME:$GITHUB_SHA
```[Install `doctl`](https://docs.digitalocean.com/reference/doctl/how-to/install/). On 1st time use of `doctl` you need to validate with `doctl auth init`.
Now use text `app.yaml` as a template for our app spec and substitute the environmental variables in it to create a new file called `update.yaml`. We set the image tag to the git SHA in GitHub actions, but for now just tag with latest:
```bash
envsubst < app.yaml > update.yaml
```Validate the `update.yaml` then create the app with `doctl`:
```bash
doctl apps spec validate update.yamldoctl apps create --spec update.yaml
```Take note of the app ID at the end: `ff95990f-5235-43dd-baba-74980e30740f` or something similar.
### Add secrets
Add a couple of secrets to the GitHub repo:
- `APP_ID`: the app ID from the initial deployment to the App Platform
- `DIGITALOCEAN_ACCESS_TOKEN`: an API token for `doctl` (make sure write is in the scope)
- `DOCKERHUB_ACCESS_TOKEN`: access token for Docker Hub (make sure write is in the scope)
- `DOCKERHUB_USERNAME`: your Docker Hub user name used for registry login### Add the workflow
This workflow will test, build, bush, deploy the app. See the `.github/workflows/deploy.yml` file for the steps.
#### Check out
Pull the latest state of the repo.
#### Add your tests
This is where you can add any tests before build/push/deploy.
#### Install doctl
We will need the `doctl` utility initialized with your `$DIGITALOCEAN_ACCESS_TOKEN`.
#### Docker build and push with cache
This is an important step. It handles the following:
- log into Docker Hub using the username and access token
- builds the new image using a previous build cache (no effect on 1st build)
- tags it with the git commit SHA
- pushed the new image to Docker HubAs it turns out, the image tag needs to be unique to trigger a pull on the App Platform. So it is best to use the git commit SHA.
Using the build cache cuts down the build time if the dependencies have not changed (in this case from 9-10 minutes to 1 minute).
#### Update app spec and publish the app
This is where we use environment variables and substitute these into contents of the `app.yaml` then save it into the `update.yaml` file.
Finally, update app in App Platform using the new `update.yaml` app spec file. The new file has the updated tag based on the commit SHA, so the image pull will happen as expected.