Skip to content

Commit

Permalink
fix(docker): adding in docker building
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Aug 14, 2024
1 parent 3b34aad commit 162ba1d
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 73 deletions.
58 changes: 58 additions & 0 deletions .github/actions/containerize/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: 'Re-usable Docker Build Flow'
description: 'Used to setup and build a docker image'
inputs:
scope:
description: 'Turbo Repo scope to run the build for'
required: true
docker-repo-name:
description: 'Docker name of the repo <account-id>.dkr.ecr.us-east-1.amazonaws.com/<name>'
required: true
app-path:
description: 'The path of where the application is located in the monorepo ie servers/<app-name>'
required: true
app-port:
description: 'The port the application runs on ie 4006'
required: true
sentry-org:
description: 'The org name used in sentry. Used to upload source maps'
required: false
default: pocket
sentry-project:
description: 'The project name used in sentry. Used to upload source maps'
required: true
push:
description: Whether or not to push the image
required: true
default: 'false'

runs:
using: 'composite'
steps:
# can be useful if you want to add emulation support with QEMU to be able to build against more platforms.
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

# action will create and boot a builder using by default the docker-container driver.
# This is not required but recommended using it to be able to build multi-platform images, export cache, etc.
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build docker image
uses: docker/build-push-action@v6
with:
push: ${{inputs['push']}}
tags: ${{inputs['docker-repo-name']}}:${{ github.sha }}
build-args: |
GIT_SHA=${{ github.sha }}
SCOPE=${{inputs['scope']}}
APP_PATH=${{inputs['app-path']}}
SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_BEARER }}
SENTRY_ORG=${{inputs['sentry-org']}}
SENTRY_PROJECT=${{inputs['sentry-project']}}
PORT=${{inputs['app-port']}}
98 changes: 98 additions & 0 deletions .github/workflows/build-and-push-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: 'Re-usable Docker Build Flow'
on:
workflow_call:
inputs:
scope:
description: 'Turbo Repo scope to run the build for'
required: true
type: string
docker-repo-name-short-hand:
description: 'Docker name of the repo <account-id>.dkr.ecr.us-east-1.amazonaws.com/<name>'
required: true
type: string
development-aws-registry:
description: 'AWS Development Account Id'
type: string
default: 410318598490.dkr.ecr.us-east-1.amazonaws.com
production-aws-registry:
description: 'AWS Development Account Id'
type: string
default: 410318598490.dkr.ecr.us-east-1.amazonaws.com
app-path:
description: 'The path of where the application is located in the monorepo ie servers/<app-name>'
required: true
type: string
app-port:
description: 'The port the application runs on ie 4006'
required: true
type: number
sentry-org:
description: 'The org name used in sentry. Used to upload source maps'
required: false
type: string
default: pocket
sentry-project:
description: 'The project name used in sentry. Used to upload source maps'
required: true
type: string

jobs:
# Let's build the image on every pull request just like we would on production
pull-request:
# Only run this job on a pull request event
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build Docker Image
# Use our re-usable containerize action
uses: ./.github/actions/containerize
with:
docker-repo-name: ${{inputs['development-aws-registry']}}/${{inputs['docker-repo-name-short-hand']}}-prod-app
app-path: ${{inputs['app-path']}}
app-port: ${{inputs['app-port']}}
sentry-project: ${{inputs['sentry-project']}}
sentry-org: ${{inputs['sentry-org']}}
scope: ${{inputs['scope']}}
# Ensure the re-usable workflow is allowed to access the secrets

development:
if: github.ref == 'refs/heads/dev'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build and Push Development Docker Image
# Use our re-usable containerize action
uses: ./.github/actions/containerize
with:
docker-repo-name: ${{inputs['development-aws-registry']}}/${{inputs['docker-repo-name-short-hand']}}-dev-app
app-path: ${{inputs['app-path']}}
app-port: ${{inputs['app-port']}}
sentry-project: ${{inputs['sentry-project']}}
sentry-org: ${{inputs['sentry-org']}}
scope: ${{inputs['scope']}}
push: false


production:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

# While we wait for docker compose to be healthy we install node and needed packages for this service
- name: Build and Push Production Docker Image
# Use our re-usable containerize action
uses: ./.github/actions/containerize
with:
docker-repo-name: ${{inputs['development-aws-registry']}}/${{inputs['docker-repo-name-short-hand']}}-prod-app
app-path: ${{inputs['app-path']}}
app-port: ${{inputs['app-port']}}
sentry-project: ${{inputs['sentry-project']}}
sentry-org: ${{inputs['sentry-org']}}
scope: ${{inputs['scope']}}
# Ensure the re-usable workflow is allowed to access the secrets
62 changes: 0 additions & 62 deletions .github/workflows/containerize.yml

This file was deleted.

12 changes: 12 additions & 0 deletions .github/workflows/list-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,16 @@ jobs:
# Only run the tests for our service
scope: 'list-api'
# Ensure the re-usable workflow is allowed to access the secrets
secrets: inherit

# Let's test the service against some real life and mocked docker services.
build-and-push-image:
uses: ./.github/workflows/build-and-push-image.yml
with:
scope: list-api
app-path: servers/list-api
app-port: 4005
sentry-project: list-api
docker-repo-name-short-hand: listapi
# Ensure the re-usable workflow is allowed to access the secrets
secrets: inherit
18 changes: 7 additions & 11 deletions .github/workflows/user-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@ jobs:
secrets: inherit

# Let's test the service against some real life and mocked docker services.
build-image:
# Only run this job on a pull request event
if: github.event_name == 'pull_request'
# Use our re-usable test integrations workflow which will use our docker compose file
uses: ./.github/workflows/containerize.yml
build-and-push-image:
uses: ./.github/workflows/build-and-push-image.yml
with:
# Only run the tests for our service
scope: 'user-api'
docker-repo-name: 410318598490.dkr.ecr.us-east-1.amazonaws.com/listapi-dev-app
app-path: servers/list-api
app-port: 4005
sentry-project: list-api
scope: user-api
app-path: servers/user-api
app-port: 4006
sentry-project: user-api
docker-repo-name-short-hand: userapi
# Ensure the re-usable workflow is allowed to access the secrets
secrets: inherit

0 comments on commit 162ba1d

Please sign in to comment.