diff --git a/.github/actions/containerize/action.yml b/.github/actions/containerize/action.yml new file mode 100644 index 000000000..e12e709b2 --- /dev/null +++ b/.github/actions/containerize/action.yml @@ -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 .dkr.ecr.us-east-1.amazonaws.com/' + required: true + app-path: + description: 'The path of where the application is located in the monorepo ie servers/' + 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']}} \ No newline at end of file diff --git a/.github/workflows/build-and-push-image.yml b/.github/workflows/build-and-push-image.yml new file mode 100644 index 000000000..a4725127f --- /dev/null +++ b/.github/workflows/build-and-push-image.yml @@ -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 .dkr.ecr.us-east-1.amazonaws.com/' + 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/' + 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 diff --git a/.github/workflows/containerize.yml b/.github/workflows/containerize.yml deleted file mode 100644 index 5886b6070..000000000 --- a/.github/workflows/containerize.yml +++ /dev/null @@ -1,62 +0,0 @@ -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: - description: 'Docker name of the repo .dkr.ecr.us-east-1.amazonaws.com/' - required: true - type: string - app-path: - description: 'The path of where the application is located in the monorepo ie servers/' - 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: - main: - runs-on: ubuntu-latest - 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: false - 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']}} \ No newline at end of file diff --git a/.github/workflows/list-api.yml b/.github/workflows/list-api.yml index 3ffc9e912..91de3e40b 100644 --- a/.github/workflows/list-api.yml +++ b/.github/workflows/list-api.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/user-api.yml b/.github/workflows/user-api.yml index 25198efa1..ed5c730e9 100644 --- a/.github/workflows/user-api.yml +++ b/.github/workflows/user-api.yml @@ -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 \ No newline at end of file