New GitHub Actions Unveiled for DigitalOcean App Platform

NewsNew GitHub Actions Unveiled for DigitalOcean App Platform

Github Actions has become the most preferred Continuous Integration and Continuous Deployment (CI/CD) platform among our customers for building and deploying their code. Previously, we offered a supported action named `app_action` that could be used to update an existing App via a Github Action.

Today, we are thrilled to announce the release of a thoroughly revamped Github Actions for App Platform, designed with enhanced pluggability to accommodate all your deployment needs.

The newly introduced deploy action serves as the core of our Github Actions ecosystem. Similar to the previous version, it allows you to update an existing app. However, it goes beyond that by enabling you to make the corresponding Github repository the single source of truth in a GitOps-style approach. This means you can now commit an AppSpec to your Github repository and manage the entire deployment process through Github Actions. There is no longer a need to directly interact with DigitalOcean, except for generating the token that the action will use.

The AppSpec within the repository can include environment variable placeholders, which are replaced before deploying the new spec. This feature can be utilized to dynamically update image references or manage your secrets using Github’s secret mechanism.

We have also taken this opportunity to enhance integration within the Github Actions ecosystem. The deploy action outputs the resulting app metadata along with the build and deployment logs from the executed deployment. Optionally, these logs can also be included in the action’s output. This metadata can be leveraged to create comprehensive integrations with App Platform, tailored to your specific requirements.

Deploy an App from Github

Deploying an app purely from Github without the need to create it out of band first is as simple as committing the respective App Spec to the repository (by default, the action looks for .do/app.yaml) and setting up an action as shown below. This will trigger the app to redeploy whenever a new commit is pushed to the main branch (ensure that `deploy_on_push` is turned off in the App Spec for this to work). Any changes made to the App Spec itself will also be applied.


name: Update App

on:
push:
branches: [main]

permissions:
contents: read

jobs:
deploy-app:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Deploy the app
uses: digitalocean/app_action/deploy@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

Deploy an App from an Image Built in the Github Action

In a slightly more complex use case, the action below builds an app from a Dockerfile in the repository within the Github Action, instead of as part of the App Platform build. The image is then deployed by digest, ensuring that this exact image is what gets deployed as part of the app.

Note that the image digest is provided as the `SAMPLE_DIGEST` environment variable. This needs to be referenced in the App Spec using the `$SAMPLE_DIGEST` notation.


on:
push:
branches: [main]

permissions:
contents: read
packages: write

jobs:
build-push-deploy-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6.5.0
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest
- name: Deploy the app
uses: digitalocean/app_action/deploy@v2
env:
SAMPLE_DIGEST: ${{ steps.push.outputs.digest }}
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

Reference the `SAMPLE_DIGEST` environment variable in your App Spec as shown below:


name: sample
services:
- name: sample
image:
registry_type: GHCR
registry: YOUR_ORG
repository: YOUR_REPO
digest: $SAMPLE_DIGEST

Pull Request Previews

Pull request previews exemplify the power of orchestration. This feature allows you to deploy a new app for every pull request and provide the respective live URL, build logs, and deployment logs to the pull request author. This helps in avoiding the merging of code that could potentially break the app in production.

The new deploy action simplifies the creation of such an integration in your repository. It includes a specialized “PR-preview-mode” that generates a unique app name for each pull request, sanitizes the app spec to avoid potential conflicts (like dropping domains and alerts), and updates all Github references to point to the respective PR’s branch.

Additionally, a new delete action has been introduced, allowing you to delete apps when a pull request is closed or merged, thereby cleaning up resources. Here is an example action that deploys an app per pull request and posts a comment with a link to the app on successful deployment or a link to the action’s logs on failure. Another action ensures that the respective app is deleted when the pull request is closed or merged.


name: App Platform Preview

on:
pull_request:
branches: [main]

permissions:
contents: read
pull-requests: write

jobs:
test:
name: preview
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Deploy the app
id: deploy
uses: digitalocean/app_action/deploy@v2
with:
deploy_pr_preview: "true"
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- uses: actions/github-script@v7
env:
BUILD_LOGS: ${{ steps.deploy.outputs.build_logs }}
DEPLOY_LOGS: ${{ steps.deploy.outputs.deploy_logs }}
with:
script: |
const { BUILD_LOGS, DEPLOY_LOGS } = process.env;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `:rocket: The app was successfully deployed at ${{ steps.deploy.outputs.app.live_url }}.`
});
- uses: actions/github-script@v7
if: failure()
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `The app failed to be deployed. Logs can be found [here](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).
## Logs

Build logs
\`\`\`
$BUILD_LOGS
\`\`\`


Deploy logs
\`\`\`
$DEPLOY_LOGS
\`\`\`
`
});


name: Delete Preview

on:
pull_request:
types: [closed]

jobs:
closed:
runs-on: ubuntu-latest
steps:
- name: delete preview app
uses: digitalocean/app_action/delete@v2
with:
from_pr_preview: "true"
ignore_not_found: "true"
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

For more details and code examples, visit the app_action Github repository. We are eager to see the integrations you come up with! Try out the new actions and elevate your app platform deployments.

For more Information, Refer to this article.

Neil S
Neil S
Neil is a highly qualified Technical Writer with an M.Sc(IT) degree and an impressive range of IT and Support certifications including MCSE, CCNA, ACA(Adobe Certified Associates), and PG Dip (IT). With over 10 years of hands-on experience as an IT support engineer across Windows, Mac, iOS, and Linux Server platforms, Neil possesses the expertise to create comprehensive and user-friendly documentation that simplifies complex technical concepts for a wide audience.
Watch & Subscribe Our YouTube Channel
YouTube Subscribe Button

Latest From Hawkdive

You May like these Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.