From 0607907e1270f3f082c6dfcd2eb786bbf70c894d Mon Sep 17 00:00:00 2001 From: Ali Bahman Date: Sat, 13 Jul 2024 14:52:22 +0100 Subject: [PATCH] DP-187 (WIP) Combine jobs --- .github/workflows/build.yml | 74 +++++++-------- .github/workflows/build_test_deploy.yaml | 110 ++++++++++++++++++++++ .github/workflows/deploy.yml | 114 +++++++++++------------ .github/workflows/test.yml | 78 ++++++++-------- 4 files changed, 243 insertions(+), 133 deletions(-) create mode 100644 .github/workflows/build_test_deploy.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 351f869b5..6a346ca0e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,37 +1,37 @@ -name: Build - -on: - push: - branches: [DP-187] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: '8.0.x' - - - name: Build .NET Project - run: | - dotnet tool restore - dotnet restore - dotnet build - - - name: Build Docker Images - run: make build-docker - - - name: Save Docker Images - run: | - mkdir -p docker_images - docker save -o docker_images/cdp-images.tar cabinetoffice/cdp-organisation-information-migrations:latest cabinetoffice/cdp-data-sharing:latest cabinetoffice/cdp-forms:latest cabinetoffice/cdp-organisation-app:latest cabinetoffice/cdp-organisation:latest cabinetoffice/cdp-person:latest cabinetoffice/cdp-tenant:latest cabinetoffice/cdp-authority:latest - - - name: Upload Docker Images - uses: actions/upload-artifact@v2 - with: - name: docker-images - path: docker_images/cdp-images.tar +#name: Build +# +#on: +# push: +# branches: [DP-187] +# +#jobs: +# build: +# runs-on: ubuntu-latest +# +# steps: +# - uses: actions/checkout@v4 +# +# - name: Setup .NET +# uses: actions/setup-dotnet@v4 +# with: +# dotnet-version: '8.0.x' +# +# - name: Build .NET Project +# run: | +# dotnet tool restore +# dotnet restore +# dotnet build +# +# - name: Build Docker Images +# run: make build-docker +# +# - name: Save Docker Images +# run: | +# mkdir -p docker_images +# docker save -o docker_images/cdp-images.tar cabinetoffice/cdp-organisation-information-migrations:latest cabinetoffice/cdp-data-sharing:latest cabinetoffice/cdp-forms:latest cabinetoffice/cdp-organisation-app:latest cabinetoffice/cdp-organisation:latest cabinetoffice/cdp-person:latest cabinetoffice/cdp-tenant:latest cabinetoffice/cdp-authority:latest +# +# - name: Upload Docker Images +# uses: actions/upload-artifact@v2 +# with: +# name: docker-images +# path: docker_images/cdp-images.tar diff --git a/.github/workflows/build_test_deploy.yaml b/.github/workflows/build_test_deploy.yaml new file mode 100644 index 000000000..5519cbfdc --- /dev/null +++ b/.github/workflows/build_test_deploy.yaml @@ -0,0 +1,110 @@ +name: CI/CD Pipeline + +on: + push: + branches: [DP-187] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' + + - name: Build .NET Project + run: | + dotnet tool restore + dotnet restore + dotnet build + + - name: Build Docker Images + run: make build-docker + + - name: Save Docker Images + run: | + docker save -o cdp-images.tar cabinetoffice/cdp-organisation-information-migrations:latest cabinetoffice/cdp-data-sharing:latest cabinetoffice/cdp-forms:latest cabinetoffice/cdp-organisation-app:latest cabinetoffice/cdp-organisation:latest cabinetoffice/cdp-person:latest cabinetoffice/cdp-tenant:latest cabinetoffice/cdp-authority:latest + + - name: Upload Docker Images as Artifacts + uses: actions/upload-artifact@v2 + with: + name: docker-images + path: cdp-images.tar + + test: + runs-on: ubuntu-latest + needs: build + + steps: + - uses: actions/checkout@v4 + + - name: Download Docker Images + uses: actions/download-artifact@v2 + with: + name: docker-images + + - name: Load Docker Images + run: docker load -i cdp-images.tar + + - name: Start services + run: make up + + - name: Run Tests + run: | + dotnet test --logger trx --results-directory TestResults + + - name: Stop services + run: make down + + deploy: + runs-on: ubuntu-latest + needs: test + if: github.ref == 'refs/heads/DP-187' + + steps: + - uses: actions/checkout@v4 + + - name: Download Docker Images + uses: actions/download-artifact@v2 + with: + name: docker-images + + - name: Load Docker Images + run: docker load -i cdp-images.tar + + - name: Set up AWS CLI + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-west-2 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Tag and Push Docker Images + run: | + IMAGE_VERSION=$(date +%Y%m%d%H%M%S) + for image in cabinetoffice/cdp-organisation-information-migrations cabinetoffice/cdp-data-sharing cabinetoffice/cdp-forms cabinetoffice/cdp-organisation-app cabinetoffice/cdp-organisation cabinetoffice/cdp-person cabinetoffice/cdp-tenant cabinetoffice/cdp-authority; do + CLEAN_IMAGE_NAME=$(echo $image | sed 's/^cabinetoffice\///') + docker tag $image:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/$CLEAN_IMAGE_NAME:$IMAGE_VERSION + docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/$CLEAN_IMAGE_NAME:$IMAGE_VERSION + done + + - name: Create Git Tag + run: | + IMAGE_VERSION=$(date +%Y%m%d%H%M%S) + git config --global user.name "github-actions" + git config --global user.email "github-actions@github.com" + git tag ${IMAGE_VERSION} + git push origin ${IMAGE_VERSION} + + - name: Store Version in SSM Parameter Store + run: | + IMAGE_VERSION=$(date +%Y%m%d%H%M%S) + aws ssm put-parameter --name "cdp-sirsi-service-version" --value "${IMAGE_VERSION}" --type String --overwrite diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2956ff28d..31a0f8d2c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,57 +1,57 @@ -name: Deploy - -on: - workflow_run: - workflows: [Test] - branches: [DP-187] - types: - - completed - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Download Docker Images - uses: actions/download-artifact@v2 - with: - name: docker-images - path: docker_images/ - - - name: Load Docker Images - run: docker load -i docker_images/cdp-images.tar - - - name: Set up AWS CLI - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: eu-west-2 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: Tag and Push Docker Images - run: | - IMAGE_VERSION=$(date +%Y%m%d%H%M%S) - for image in cabinetoffice/cdp-organisation-information-migrations cabinetoffice/cdp-data-sharing cabinetoffice/cdp-forms cabinetoffice/cdp-organisation-app cabinetoffice/cdp-organisation cabinetoffice/cdp-person cabinetoffice/cdp-tenant cabinetoffice/cdp-authority; do - CLEAN_IMAGE_NAME=$(echo $image | sed 's/^cabinetoffice\///') - docker tag $image:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/$CLEAN_IMAGE_NAME:$IMAGE_VERSION - docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/$CLEAN_IMAGE_NAME:$IMAGE_VERSION - done - - - name: Create Git Tag - run: | - IMAGE_VERSION=$(date +%Y%m%d%H%M%S) - git config --global user.name "github-actions" - git config --global user.email "github-actions@github.com" - git tag ${IMAGE_VERSION} - git push origin ${IMAGE_VERSION} - - - name: Store Version in SSM Parameter Store - run: | - IMAGE_VERSION=$(date +%Y%m%d%H%M%S) - aws ssm put-parameter --name "cdp-sirsi-service-version" --value "${IMAGE_VERSION}" --type String --overwrite +#name: Deploy +# +#on: +# workflow_run: +# workflows: [Test] +# branches: [DP-187] +# types: +# - completed +# +#jobs: +# deploy: +# runs-on: ubuntu-latest +# +# steps: +# - uses: actions/checkout@v4 +# +# - name: Download Docker Images +# uses: actions/download-artifact@v2 +# with: +# name: docker-images +# path: docker_images/ +# +# - name: Load Docker Images +# run: docker load -i docker_images/cdp-images.tar +# +# - name: Set up AWS CLI +# uses: aws-actions/configure-aws-credentials@v1 +# with: +# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} +# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} +# aws-region: eu-west-2 +# +# - name: Login to Amazon ECR +# id: login-ecr +# uses: aws-actions/amazon-ecr-login@v1 +# +# - name: Tag and Push Docker Images +# run: | +# IMAGE_VERSION=$(date +%Y%m%d%H%M%S) +# for image in cabinetoffice/cdp-organisation-information-migrations cabinetoffice/cdp-data-sharing cabinetoffice/cdp-forms cabinetoffice/cdp-organisation-app cabinetoffice/cdp-organisation cabinetoffice/cdp-person cabinetoffice/cdp-tenant cabinetoffice/cdp-authority; do +# CLEAN_IMAGE_NAME=$(echo $image | sed 's/^cabinetoffice\///') +# docker tag $image:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/$CLEAN_IMAGE_NAME:$IMAGE_VERSION +# docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/$CLEAN_IMAGE_NAME:$IMAGE_VERSION +# done +# +# - name: Create Git Tag +# run: | +# IMAGE_VERSION=$(date +%Y%m%d%H%M%S) +# git config --global user.name "github-actions" +# git config --global user.email "github-actions@github.com" +# git tag ${IMAGE_VERSION} +# git push origin ${IMAGE_VERSION} +# +# - name: Store Version in SSM Parameter Store +# run: | +# IMAGE_VERSION=$(date +%Y%m%d%H%M%S) +# aws ssm put-parameter --name "cdp-sirsi-service-version" --value "${IMAGE_VERSION}" --type String --overwrite diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f5874673..f52394bc9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,39 +1,39 @@ -name: Test - -on: - workflow_run: - workflows: [Build] - branches: [DP-187] - types: - - completed - -jobs: - test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: '8.0.x' - - - name: Download Docker Images - uses: actions/download-artifact@v2 - with: - name: docker-images - path: docker_images/ - - - name: Load Docker Images - run: docker load -i docker_images/cdp-images.tar - - - name: Start services - run: make up - - - name: Run Tests - run: | - dotnet test --logger trx --results-directory TestResults - - - name: Stop services - run: make down +#name: Test +# +#on: +# workflow_run: +# workflows: [Build] +# branches: [DP-187] +# types: +# - completed +# +#jobs: +# test: +# runs-on: ubuntu-latest +# +# steps: +# - uses: actions/checkout@v4 +# +# - name: Setup .NET +# uses: actions/setup-dotnet@v4 +# with: +# dotnet-version: '8.0.x' +# +# - name: Download Docker Images +# uses: actions/download-artifact@v2 +# with: +# name: docker-images +# path: docker_images/ +# +# - name: Load Docker Images +# run: docker load -i docker_images/cdp-images.tar +# +# - name: Start services +# run: make up +# +# - name: Run Tests +# run: | +# dotnet test --logger trx --results-directory TestResults +# +# - name: Stop services +# run: make down