diff --git a/.github/workflows/cdk_package_code.yml b/.github/workflows/cdk_package_code.yml index 8d807f9..dda9329 100644 --- a/.github/workflows/cdk_package_code.yml +++ b/.github/workflows/cdk_package_code.yml @@ -42,15 +42,19 @@ jobs: run: | make install - - shell: bash - name: build docker image + - name: 'Tar files' run: | - make build-deployment-container-image - docker save "eps-aws-dashboards" | gzip > eps-aws-dashboards.tar.gz + tar -rf artifact.tar \ + .tool-versions \ + packages \ + node_modules \ + package.json \ + package-lock.json \ + tsconfig.defaults.json \ + cdk.json - uses: actions/upload-artifact@v4 name: upload build artifact with: - name: docker_artifact - path: | - eps-aws-dashboards.tar.gz + name: build_artifact + path: artifact.tar diff --git a/.github/workflows/cdk_release_code.yml b/.github/workflows/cdk_release_code.yml index 8b0bd34..fbba270 100644 --- a/.github/workflows/cdk_release_code.yml +++ b/.github/workflows/cdk_release_code.yml @@ -83,28 +83,63 @@ jobs: DEV_CLOUD_FORMATION_EXECUTE_LAMBDA_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_EXECUTE_LAMBDA_ROLE }} - name: Configure AWS Credentials - id: connect-aws + id: connect-aws-pull-image uses: aws-actions/configure-aws-credentials@v4 with: aws-region: eu-west-2 - role-to-assume: ${{ secrets.CLOUD_FORMATION_DEPLOY_ROLE }} - role-session-name: eps-aws-dashboards-deployment - output-credentials: true + role-to-assume: ${{ secrets.CDK_PULL_IMAGE_ROLE }} + role-session-name: eps-aws-dashboards-pull-image - - name: docker_artifact download + - name: build_artifact download uses: actions/download-artifact@v4 with: - name: docker_artifact - path: . + name: build_artifact + + - name: extract build_artifact + run: | + mkdir -p .build + tar -xf artifact.tar -C .build + + - name: Retrieve AWS Account ID + id: retrieve-account-id + run: echo "ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)" >> "$GITHUB_ENV" + + - name: Login to Amazon ECR + id: login-ecr + run: | + aws ecr get-login-password --region eu-west-2 | docker login --username AWS --password-stdin ${{ env.ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com + + - name: Pull cdk-utils-build from Amazon ECR + run: | + docker pull "${{ env.ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/cdk-utils-build-repo:latest" + docker tag "${{ env.ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/cdk-utils-build-repo:latest" cdk-utils-build-repo:latest + + - name: Configure AWS Credentials + id: connect-aws + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-region: eu-west-2 + role-to-assume: ${{ secrets.CLOUD_FORMATION_DEPLOY_ROLE }} + role-session-name: prescription-clinical-tracker-ui-deployment + output-credentials: true - - name: Extract eps-aws-dashboards docker image - id: extract-eps-aws-dashboards-image + - name: fix cdk.json for deployment run: | - docker load < eps-aws-dashboards.tar.gz + jq \ + --arg stackName "${{ inputs.stack_name }}" \ + --arg VERSION_NUMBER "${{ inputs.VERSION_NUMBER }}" \ + --arg COMMIT_ID "${{ inputs.COMMIT_ID }}" \ + '.context += { + "stackName": $stackName, + "VERSION_NUMBER": $VERSION_NUMBER, + "COMMIT_ID": $COMMIT_ID}' \ + .build/cdk.json > .build/cdk.new.json + mv .build/cdk.new.json .build/cdk.json - name: Show diff run: | docker run \ + -v "$(pwd)/.build":/home/cdkuser/workspace/ \ -e AWS_ACCESS_KEY_ID=${{ steps.connect-aws.outputs.aws-access-key-id }} \ -e AWS_SECRET_ACCESS_KEY=${{ steps.connect-aws.outputs.aws-secret-access-key }} \ -e AWS_SESSION_TOKEN=${{ steps.connect-aws.outputs.aws-session-token }} \ @@ -114,12 +149,14 @@ jobs: -e COMMIT_ID="${{ inputs.COMMIT_ID}}" \ -e SHOW_DIFF="true" \ -e DEPLOY_CODE="false" \ - eps-aws-dashboards + -e CDK_APP_PATH="packages/cdk/bin/DashboardsApp.ts" \ + cdk-utils-build-repo:latest shell: bash - name: Deploy code run: | docker run \ + -v "$(pwd)/.build":/home/cdkuser/workspace/ \ -e AWS_ACCESS_KEY_ID=${{ steps.connect-aws.outputs.aws-access-key-id }} \ -e AWS_SECRET_ACCESS_KEY=${{ steps.connect-aws.outputs.aws-secret-access-key }} \ -e AWS_SESSION_TOKEN=${{ steps.connect-aws.outputs.aws-session-token }} \ @@ -129,7 +166,8 @@ jobs: -e COMMIT_ID="${{ inputs.COMMIT_ID}}" \ -e SHOW_DIFF="false" \ -e DEPLOY_CODE="true" \ - eps-aws-dashboards + -e CDK_APP_PATH="packages/cdk/bin/DashboardsApp.ts" \ + cdk-utils-build-repo:latest shell: bash - name: create_int_release_notes diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 03f2607..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,49 +0,0 @@ -FROM ubuntu:24.04 -RUN apt-get update \ - && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y upgrade - -RUN export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends ca-certificates curl git jq make unzip wget \ - && apt-get clean - -# Install aws stuff -ADD https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip /tmp/awscliv2.zip -RUN unzip /tmp/awscliv2.zip -d /tmp/aws-cli && \ - /tmp/aws-cli/aws/install && \ - rm tmp/awscliv2.zip && \ - rm -rf /tmp/aws-cli - -RUN useradd -ms /bin/bash cdkuser -RUN chown -R cdkuser /home/cdkuser -WORKDIR /home/cdkuser -USER cdkuser - -# Install ASDF -RUN git clone https://github.com/asdf-vm/asdf.git /home/cdkuser/.asdf --branch v0.14.1; \ - echo '. /home/cdkuser/.asdf/asdf.sh' >> ~/.bashrc; \ - echo '. /home/cdkuser/.asdf/completions/asdf.bash' >> ~/.bashrc; \ - echo 'PATH="$PATH:/home/cdkuser/.asdf/bin/"' >> ~/.bashrc; - -ENV PATH="$PATH:/home/cdkuser/.asdf/bin/:/home/cdkuser/node_modules/.bin" - -# Install ASDF plugins -RUN asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git - -# Rremove ruby, python, poetry from asdf install -COPY --chown=cdkuser .tool-versions /home/cdkuser/.tool-versions -RUN sed -i -n '/nodejs/p' /home/cdkuser/.tool-versions - -RUN asdf install; \ - asdf reshim nodejs - -# Copy files needed for deployment -COPY --chown=cdkuser packages /home/cdkuser/packages -COPY --chown=cdkuser Makefile /home/cdkuser/ -COPY --chown=cdkuser node_modules /home/cdkuser/node_modules -COPY --chown=cdkuser package.json /home/cdkuser/ -COPY --chown=cdkuser package-lock.json /home/cdkuser/ -COPY --chown=cdkuser tsconfig.defaults.json /home/cdkuser/ -COPY --chown=cdkuser docker/entrypoint.sh /home/cdkuser/ - -ENTRYPOINT ["/home/cdkuser/entrypoint.sh"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh deleted file mode 100755 index 3323e0d..0000000 --- a/docker/entrypoint.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -# shellcheck source=/dev/null -source /home/cdkuser/.asdf/asdf.sh - -epsZoneId=$(aws cloudformation list-exports --output json | jq -r '.Exports[] | select(.Name == "eps-route53-resources:EPS-ZoneID") | .Value' | grep -o '[^:]*$') -epsDomain=$(aws cloudformation list-exports --output json | jq -r '.Exports[] | select(.Name == "eps-route53-resources:EPS-domain") | .Value' | grep -o '[^:]*$') -export epsZoneId -export epsDomain -export REQUIRE_APPROVAL=never -if [ "${SHOW_DIFF}" = "true" ] -then - make cdk-diff -fi -if [ "${DEPLOY_CODE}" = "true" ] -then - make cdk-deploy -fi