|
2 | 2 | title: "Digital Ocean Apps" |
3 | 3 | --- |
4 | 4 |
|
| 5 | +import GithubActionsWithPrebuiltImagesSnippet from '/snippets/github-actions-with-prebuilt-docker-images-for-do.mdx'; |
| 6 | + |
5 | 7 | There is a simplified deployment type without Kubernetes. This type is **recommended** for most new applications because it allows you to set up infrastructure faster and doesn't require additional DevOps knowledge from the development team. You can switch to a more complex Kubernetes solution when your application will be at scale. |
6 | 8 |
|
7 | 9 | <Tip> |
@@ -238,322 +240,7 @@ Done! Application deployed and can be accessed by provided domain. |
238 | 240 |  |
239 | 241 |
|
240 | 242 | ## 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 | | - |
247 | | - |
248 | | -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. |
249 | | - |
250 | | - |
251 | | - |
252 | | -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. |
253 | | - |
254 | | -**API Build and Push Docker Image GH Action:** |
255 | | -```yaml |
256 | | -name: Build and Push Staging API Image to DigitalOcean |
257 | | - |
258 | | -on: |
259 | | - push: |
260 | | - branches: [main] |
261 | | - paths: |
262 | | - - "apps/api/**" |
263 | | - - "packages/**" |
264 | | - workflow_dispatch: |
265 | | - |
266 | | -permissions: |
267 | | - contents: read |
268 | | - packages: write |
269 | | - |
270 | | -jobs: |
271 | | - build: |
272 | | - name: Build and Push Docker Images |
273 | | - runs-on: ubuntu-latest |
274 | | - strategy: |
275 | | - matrix: |
276 | | - include: |
277 | | - - app_name: api |
278 | | - dockerfile: apps/api/Dockerfile |
279 | | - - app_name: migrator |
280 | | - dockerfile: apps/api/Dockerfile.migrator |
281 | | - - app_name: scheduler |
282 | | - dockerfile: apps/api/Dockerfile.scheduler |
283 | | - steps: |
284 | | - - name: Checkout code |
285 | | - uses: actions/checkout@v4 |
286 | | - |
287 | | - - name: Set up QEMU |
288 | | - uses: docker/setup-qemu-action@v3 |
289 | | - |
290 | | - - name: Set up Docker Buildx |
291 | | - uses: docker/setup-buildx-action@v3 |
292 | | - |
293 | | - - name: Login to Docker Hub |
294 | | - uses: docker/login-action@v3 |
295 | | - with: |
296 | | - registry: registry.digitalocean.com |
297 | | - username: ${{ secrets.DO_USERNAME }} |
298 | | - password: ${{ secrets.DO_ACCESS_TOKEN }} |
299 | | - |
300 | | - - name: Build and Push Docker image |
301 | | - uses: docker/build-push-action@v5 |
302 | | - with: |
303 | | - context: . |
304 | | - push: true |
305 | | - platforms: linux/amd64 |
306 | | - file: ${{ matrix.dockerfile }} |
307 | | - tags: registry.digitalocean.com/ship-demo/ship-demo-${{ matrix.app_name }}:${{ github.sha }} |
308 | | - target: runner |
309 | | - cache-from: type=gha |
310 | | - cache-to: type=gha,mode=max |
311 | | -``` |
312 | | -
|
313 | | -**WEB Build and Push Docker Image GH Action:** |
314 | | -```yaml |
315 | | -name: Build and Push Staging Web Image to DigitalOcean |
316 | | - |
317 | | -on: |
318 | | - push: |
319 | | - branches: [main] |
320 | | - paths: |
321 | | - - "apps/web/**" |
322 | | - - "packages/**" |
323 | | - workflow_dispatch: |
324 | | - |
325 | | -permissions: |
326 | | - contents: read |
327 | | - packages: write |
328 | | - |
329 | | -jobs: |
330 | | - build: |
331 | | - name: Build and Push Docker Images |
332 | | - runs-on: ubuntu-latest |
333 | | - steps: |
334 | | - - name: Checkout code |
335 | | - uses: actions/checkout@v4 |
336 | | - |
337 | | - - name: Set up QEMU |
338 | | - uses: docker/setup-qemu-action@v3 |
339 | | - |
340 | | - - name: Set up Docker Buildx |
341 | | - uses: docker/setup-buildx-action@v3 |
342 | | - |
343 | | - - name: Login to Docker Hub |
344 | | - uses: docker/login-action@v3 |
345 | | - with: |
346 | | - registry: registry.digitalocean.com |
347 | | - username: ${{ secrets.DO_USERNAME }} |
348 | | - password: ${{ secrets.DO_ACCESS_TOKEN }} |
349 | | - |
350 | | - - name: Build and Push Docker image |
351 | | - uses: docker/build-push-action@v5 |
352 | | - with: |
353 | | - context: . |
354 | | - push: true |
355 | | - platforms: linux/amd64 |
356 | | - file: ./apps/web/Dockerfile |
357 | | - tags: registry.digitalocean.com/ship-demo/ship-demo-web:${{ github.sha }} |
358 | | - target: runner |
359 | | - cache-from: type=gha |
360 | | - cache-to: type=gha,mode=max |
361 | | - |
362 | | -``` |
363 | | - |
364 | | -3. Add 3 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. |
365 | | - |
366 | | - |
367 | | - |
368 | | - |
369 | | - |
370 | | -4. Navigate to your DigitalOcean Container Registry. You should see 4 newly added repositories, as shown in the screenshot below. |
371 | | - |
372 | | - |
373 | | - |
374 | | -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. The scheduler is placed in the `workers` section. The api is placed in the `services` section. You can also find it by name of the resource. |
375 | | - |
376 | | -6. Add `image` variable for api, migrator and scheduler. You can check image `tag` in your DigitalOcean Container Registry. |
377 | | - |
378 | | -**Image configuration :** |
379 | | -```yaml |
380 | | -image: |
381 | | - registry: YOUR_DO_REGISTRY_NAME |
382 | | - registry_type: DOCR |
383 | | - repository: YOUR_DO_REPOSITORY_NAME |
384 | | - tag: YOUR_RECENT_IMAGE_TAG |
385 | | -``` |
386 | | -
|
387 | | - |
388 | | -
|
389 | | - |
390 | | -
|
391 | | - |
392 | | -
|
393 | | -7. Do the same actions for web app. |
394 | | -
|
395 | | - |
396 | | -
|
397 | | -8. Replace the old deployment action with the new one and remove old two actions: `Build and Push Staging API Image to DigitalOcean` and `Build and Push Staging Web Image to DigitalOcean`. |
398 | | - |
399 | | -**New API deployment github action:** |
400 | | -```yaml |
401 | | -name: "Staging application API deployment" |
402 | | -
|
403 | | -on: |
404 | | - push: |
405 | | - branches: [main] |
406 | | - paths: |
407 | | - - "apps/api/**" |
408 | | - - "packages/**" |
409 | | - workflow_dispatch: |
410 | | - inputs: |
411 | | - logLevel: |
412 | | - description: "Log level" |
413 | | - required: true |
414 | | - default: "warning" |
415 | | - tags: |
416 | | - description: "Test scenario" |
417 | | - required: false |
418 | | -
|
419 | | -permissions: |
420 | | - contents: read |
421 | | - packages: write |
422 | | -
|
423 | | -jobs: |
424 | | - build: |
425 | | - name: Build and Push Docker Images |
426 | | - runs-on: ubuntu-latest |
427 | | - strategy: |
428 | | - matrix: |
429 | | - include: |
430 | | - - app_name: api |
431 | | - dockerfile: apps/api/Dockerfile |
432 | | - - app_name: migrator |
433 | | - dockerfile: apps/api/Dockerfile.migrator |
434 | | - - app_name: scheduler |
435 | | - dockerfile: apps/api/Dockerfile.scheduler |
436 | | - steps: |
437 | | - - name: Checkout code |
438 | | - uses: actions/checkout@v4 |
439 | | -
|
440 | | - - name: Set up QEMU |
441 | | - uses: docker/setup-qemu-action@v3 |
442 | | -
|
443 | | - - name: Set up Docker Buildx |
444 | | - uses: docker/setup-buildx-action@v3 |
445 | | -
|
446 | | - - name: Login to Docker Hub |
447 | | - uses: docker/login-action@v3 |
448 | | - with: |
449 | | - registry: registry.digitalocean.com |
450 | | - username: ${{ secrets.DO_USERNAME }} |
451 | | - password: ${{ secrets.DO_ACCESS_TOKEN }} |
452 | | -
|
453 | | - - name: Build and Push Docker image |
454 | | - uses: docker/build-push-action@v5 |
455 | | - with: |
456 | | - context: . |
457 | | - push: true |
458 | | - platforms: linux/amd64 |
459 | | - file: ${{ matrix.dockerfile }} |
460 | | - tags: registry.digitalocean.com/ship-demo/ship-demo-${{ matrix.app_name }}:${{ github.sha }} |
461 | | - target: runner |
462 | | - cache-from: type=gha |
463 | | - cache-to: type=gha,mode=max |
464 | | -
|
465 | | - deploy: |
466 | | - name: Deploy to DigitalOcean |
467 | | - runs-on: ubuntu-latest |
468 | | - needs: build |
469 | | - steps: |
470 | | - - name: Deploy to DigitalOcean App Platform |
471 | | - uses: digitalocean/app_action/deploy@v2 |
472 | | - env: |
473 | | - IMAGE_TAG_SHIP_DEMO_API: ${{ github.sha }} |
474 | | - IMAGE_TAG_SHIP_DEMO_MIGRATOR: ${{ github.sha }} |
475 | | - IMAGE_TAG_SHIP_DEMO_SCHEDULER: ${{ github.sha }} |
476 | | - with: |
477 | | - token: ${{ secrets.DO_ACCESS_TOKEN }} |
478 | | - app_name: ${{ secrets.DO_API_STAGING_APP_NAME }} |
479 | | -``` |
480 | | - |
481 | | -**New WEB deployment github action:** |
482 | | -```yaml |
483 | | -name: "Staging application Web deployment" |
484 | | -
|
485 | | -on: |
486 | | - push: |
487 | | - branches: [main] |
488 | | - paths: |
489 | | - - "apps/web/**" |
490 | | - - "packages/**" |
491 | | - workflow_dispatch: |
492 | | - inputs: |
493 | | - logLevel: |
494 | | - description: "Log level" |
495 | | - required: true |
496 | | - default: "warning" |
497 | | - tags: |
498 | | - description: "Test scenario" |
499 | | - required: false |
500 | | -
|
501 | | -jobs: |
502 | | - build: |
503 | | - name: Build and Push Docker Images |
504 | | - runs-on: ubuntu-latest |
505 | | - steps: |
506 | | - - name: Checkout code |
507 | | - uses: actions/checkout@v4 |
508 | | -
|
509 | | - - name: Set up QEMU |
510 | | - uses: docker/setup-qemu-action@v3 |
511 | | -
|
512 | | - - name: Set up Docker Buildx |
513 | | - uses: docker/setup-buildx-action@v3 |
514 | | -
|
515 | | - - name: Login to Docker Hub |
516 | | - uses: docker/login-action@v3 |
517 | | - with: |
518 | | - registry: registry.digitalocean.com |
519 | | - username: ${{ secrets.DO_USERNAME }} |
520 | | - password: ${{ secrets.DO_ACCESS_TOKEN }} |
521 | | -
|
522 | | - - name: Build and Push Docker image |
523 | | - uses: docker/build-push-action@v5 |
524 | | - with: |
525 | | - context: . |
526 | | - push: true |
527 | | - platforms: linux/amd64 |
528 | | - file: ./apps/web/Dockerfile |
529 | | - tags: registry.digitalocean.com/ship-demo/ship-demo-web:${{ github.sha }} |
530 | | - target: runner |
531 | | - cache-from: type=gha |
532 | | - cache-to: type=gha,mode=max |
533 | | - build-args: | |
534 | | - APP_ENV=staging |
535 | | -
|
536 | | - deploy: |
537 | | - name: Deploy to DigitalOcean |
538 | | - runs-on: ubuntu-latest |
539 | | - needs: build |
540 | | - steps: |
541 | | - - name: Deploy to DigitalOcean App Platform |
542 | | - uses: digitalocean/app_action/deploy@v2 |
543 | | - env: |
544 | | - IMAGE_TAG_SHIP_DEMO_WEB: ${{ github.sha }} |
545 | | - with: |
546 | | - token: ${{ secrets.DO_ACCESS_TOKEN }} |
547 | | - app_name: ${{ secrets.DO_WEB_STAGING_APP_NAME }} |
548 | | -``` |
549 | | - |
550 | | -<Note> |
551 | | - The name of the environment variable for the image tag must meet this requirement IMAGE_TAG_$component-name. |
552 | | -</Note> |
553 | | - |
554 | | -For production deployments, **prebuilt container images** provide better consistency and reliability. Prebuilt container images in GitHub Actions deploy faster than DigitalOcean-managed builds because the images are built in CI/CD and pushed ready-to-use, while DO builds them during deployment. See the comparison below. |
555 | | - |
556 | | - |
| 243 | +<GithubActionsWithPrebuiltImagesSnippet/> |
557 | 244 |
|
558 | 245 | ## Set up migrator and scheduler (Optional) |
559 | 246 |
|
|
0 commit comments