Skip to content

Commit 849c0fd

Browse files
committed
feat: Add docs for prebuilt docker images github actions
1 parent 79f27b2 commit 849c0fd

File tree

1 file changed

+296
-0
lines changed

1 file changed

+296
-0
lines changed

docs/deployment/digital-ocean-apps.mdx

Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,302 @@ Done! Application deployed and can be accessed by provided domain.
237237

238238
![Deployed application](/images/deployed-application.png)
239239

240+
## Github Actions with prebuilt Container Images (Optional)
241+
242+
Deploying an application to DigitalOcean can be done using prebuilt container images stored in a container registry such as [Digital Ocean Container Registry](https://www.digitalocean.com/products/container-registry). Using prebuilt images helps speed up deployment, eliminate the need to install dependencies on the server, and ensure build reproducibility.
243+
244+
To use prebuilt container images, navigate to the DigitalOcean Container Registry tab and click the Create a Container Registry button.
245+
246+
1. Select the Basic plan, choose the region that matches your app’s region, specify a name for the container registry, and click Create Registry.
247+
248+
2. Add two new GitHub Actions workflows to build and push updated images so they can be attached to your DigitalOcean Apps. Don’t forget to replace `registry.digitalocean.com/ship-demo/ship-demo-${{ matrix.app_name }}:${{ github.sha }}` with your own values from DigitalOcean.
249+
250+
**API Build and Push Docker Image GH Action:**
251+
```yaml
252+
name: Build and Push Staging API Image to DigitalOcean
253+
254+
on:
255+
push:
256+
branches: [main]
257+
paths:
258+
- "apps/api/**"
259+
- "packages/**"
260+
workflow_dispatch:
261+
262+
permissions:
263+
contents: read
264+
packages: write
265+
266+
jobs:
267+
build:
268+
name: Build and Push Docker Images
269+
runs-on: ubuntu-latest
270+
strategy:
271+
matrix:
272+
include:
273+
- app_name: api
274+
dockerfile: apps/api/Dockerfile
275+
- app_name: migrator
276+
dockerfile: apps/api/Dockerfile.migrator
277+
- app_name: scheduler
278+
dockerfile: apps/api/Dockerfile.scheduler
279+
steps:
280+
- name: Checkout code
281+
uses: actions/checkout@v4
282+
283+
- name: Set up QEMU
284+
uses: docker/setup-qemu-action@v3
285+
286+
- name: Set up Docker Buildx
287+
uses: docker/setup-buildx-action@v3
288+
289+
- name: Login to Docker Hub
290+
uses: docker/login-action@v3
291+
with:
292+
registry: registry.digitalocean.com
293+
username: ${{ secrets.DO_USERNAME }}
294+
password: ${{ secrets.DO_ACCESS_TOKEN }}
295+
296+
- name: Build and Push Docker image
297+
uses: docker/build-push-action@v5
298+
with:
299+
context: .
300+
push: true
301+
platforms: linux/amd64
302+
file: ${{ matrix.dockerfile }}
303+
tags: registry.digitalocean.com/ship-demo/ship-demo-${{ matrix.app_name }}:${{ github.sha }}
304+
target: runner
305+
cache-from: type=gha
306+
cache-to: type=gha,mode=max
307+
```
308+
309+
**WEB Build and Push Docker Image GH Action:**
310+
```yaml
311+
name: Build and Push Staging Web Image to DigitalOcean
312+
313+
on:
314+
push:
315+
branches: [main]
316+
paths:
317+
- "apps/web/**"
318+
- "packages/**"
319+
workflow_dispatch:
320+
321+
permissions:
322+
contents: read
323+
packages: write
324+
325+
jobs:
326+
build:
327+
name: Build and Push Docker Images
328+
runs-on: ubuntu-latest
329+
steps:
330+
- name: Checkout code
331+
uses: actions/checkout@v4
332+
333+
- name: Set up QEMU
334+
uses: docker/setup-qemu-action@v3
335+
336+
- name: Set up Docker Buildx
337+
uses: docker/setup-buildx-action@v3
338+
339+
- name: Login to Docker Hub
340+
uses: docker/login-action@v3
341+
with:
342+
registry: registry.digitalocean.com
343+
username: ${{ secrets.DO_USERNAME }}
344+
password: ${{ secrets.DO_ACCESS_TOKEN }}
345+
346+
- name: Build and Push Docker image
347+
uses: docker/build-push-action@v5
348+
with:
349+
context: .
350+
push: true
351+
platforms: linux/amd64
352+
file: ./apps/api/Dockerfile
353+
tags: registry.digitalocean.com/ship-demo/ship-demo-web:${{ github.sha }}
354+
target: runner
355+
cache-from: type=gha
356+
cache-to: type=gha,mode=max
357+
358+
```
359+
360+
3. Add three new github secrets: `DO_USERNAME` (the email of your DigitalOcean account), `DO_WEB_STAGING_APP_NAME` (the name of the web app), and `DO_API_STAGING_APP_NAME` (the name of the API app). And run 2 new workflows manually to push the initial images to the DigitalOcean Container Registry.
361+
362+
4. Navigate to your DigitalOcean Container Registry. You should see 4 newly added repositories, as shown in the screenshot below.
363+
364+
5. Navigate to Application Spec `(settings tab)`. Remove `dockerfile_path`, `github`, `source_dir` variables for migrator, scheduler and api. Migrator is placed in the `jobs` section. You can also find it by name of the resource. The scheduler is placed in the `workers` section. The api is placed in the `services` section.
365+
366+
6. Add `image` variable for api, migrator and scheduler. You can check image `tag` in your DigitalOcean Container Registry.
367+
368+
**Image configuration :**
369+
```yaml
370+
image:
371+
registry: YOUR_DO_REGISTRY_NAME
372+
registry_type: DOCR
373+
repository: YOUR_DO_REPOSITORY_NAME
374+
tag: YOUR_RECENT_IMAGE_TAG
375+
```
376+
377+
7. Do the same actions for web app.
378+
379+
8. Replace the old deployment action with the new one and remove the two actions: `Build and Push Staging API Image to DigitalOcean` and `Build and Push Staging Web Image to DigitalOcean`.
380+
381+
**New API deployment github action:**
382+
```yaml
383+
name: "Staging application API deployment"
384+
385+
on:
386+
push:
387+
branches: [main]
388+
paths:
389+
- "apps/api/**"
390+
- "packages/**"
391+
workflow_dispatch:
392+
inputs:
393+
logLevel:
394+
description: "Log level"
395+
required: true
396+
default: "warning"
397+
tags:
398+
description: "Test scenario"
399+
required: false
400+
401+
permissions:
402+
contents: read
403+
packages: write
404+
405+
jobs:
406+
build:
407+
name: Build and Push Docker Images
408+
runs-on: ubuntu-latest
409+
strategy:
410+
matrix:
411+
include:
412+
- app_name: api
413+
dockerfile: apps/api/Dockerfile
414+
- app_name: migrator
415+
dockerfile: apps/api/Dockerfile.migrator
416+
- app_name: scheduler
417+
dockerfile: apps/api/Dockerfile.scheduler
418+
steps:
419+
- name: Checkout code
420+
uses: actions/checkout@v4
421+
422+
- name: Set up QEMU
423+
uses: docker/setup-qemu-action@v3
424+
425+
- name: Set up Docker Buildx
426+
uses: docker/setup-buildx-action@v3
427+
428+
- name: Login to Docker Hub
429+
uses: docker/login-action@v3
430+
with:
431+
registry: registry.digitalocean.com
432+
username: ${{ secrets.DO_USERNAME }}
433+
password: ${{ secrets.DO_ACCESS_TOKEN }}
434+
435+
- name: Build and Push Docker image
436+
uses: docker/build-push-action@v5
437+
with:
438+
context: .
439+
push: true
440+
platforms: linux/amd64
441+
file: ${{ matrix.dockerfile }}
442+
tags: registry.digitalocean.com/ship-demo/ship-demo-${{ matrix.app_name }}:${{ github.sha }}
443+
target: runner
444+
cache-from: type=gha
445+
cache-to: type=gha,mode=max
446+
447+
deploy:
448+
name: Deploy to DigitalOcean
449+
runs-on: ubuntu-latest
450+
needs: build
451+
steps:
452+
- name: Deploy to DigitalOcean App Platform
453+
uses: digitalocean/app_action/deploy@v2
454+
env:
455+
IMAGE_TAG_SHIP_DEMO_API: ${{ github.sha }}
456+
IMAGE_TAG_SHIP_DEMO_MIGRATOR: ${{ github.sha }}
457+
IMAGE_TAG_SHIP_DEMO_SCHEDULER: ${{ github.sha }}
458+
with:
459+
token: ${{ secrets.DO_ACCESS_TOKEN }}
460+
app_name: ${{ secrets.DO_API_STAGING_APP_NAME }}
461+
```
462+
463+
**New WEB deployment github action:**
464+
```yaml
465+
name: "Staging application Web deployment"
466+
467+
on:
468+
push:
469+
branches: [main]
470+
paths:
471+
- "apps/web/**"
472+
- "packages/**"
473+
workflow_dispatch:
474+
inputs:
475+
logLevel:
476+
description: "Log level"
477+
required: true
478+
default: "warning"
479+
tags:
480+
description: "Test scenario"
481+
required: false
482+
483+
jobs:
484+
build:
485+
name: Build and Push Docker Images
486+
runs-on: ubuntu-latest
487+
steps:
488+
- name: Checkout code
489+
uses: actions/checkout@v4
490+
491+
- name: Set up QEMU
492+
uses: docker/setup-qemu-action@v3
493+
494+
- name: Set up Docker Buildx
495+
uses: docker/setup-buildx-action@v3
496+
497+
- name: Login to Docker Hub
498+
uses: docker/login-action@v3
499+
with:
500+
registry: registry.digitalocean.com
501+
username: ${{ secrets.DO_USERNAME }}
502+
password: ${{ secrets.DO_ACCESS_TOKEN }}
503+
504+
- name: Build and Push Docker image
505+
uses: docker/build-push-action@v5
506+
with:
507+
context: .
508+
push: true
509+
platforms: linux/amd64
510+
file: ./apps/web/Dockerfile
511+
tags: registry.digitalocean.com/ship-demo/ship-demo-web:${{ github.sha }}
512+
target: runner
513+
cache-from: type=gha
514+
cache-to: type=gha,mode=max
515+
build-args: |
516+
APP_ENV=staging
517+
518+
deploy:
519+
name: Deploy to DigitalOcean
520+
runs-on: ubuntu-latest
521+
needs: build
522+
steps:
523+
- name: Deploy to DigitalOcean App Platform
524+
uses: digitalocean/app_action/deploy@v2
525+
env:
526+
IMAGE_TAG_SHIP_DEMO_WEB: ${{ github.sha }}
527+
with:
528+
token: ${{ secrets.DO_ACCESS_TOKEN }}
529+
app_name: ${{ secrets.DO_WEB_STAGING_APP_NAME }}
530+
```
531+
532+
<Note>
533+
The name of the environment variable for the image tag must meet this requirement IMAGE_TAG_$component-name.
534+
</Note>
535+
240536
## Set up migrator and scheduler (Optional)
241537

242538
Digital Ocean Apps allows configuring additional resources within one application, which can serve as background workers and jobs, and a scheduler to run before/after the deployment process.

0 commit comments

Comments
 (0)