-
Notifications
You must be signed in to change notification settings - Fork 9
NIAD-3175: create GitHub Actions build #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b6145d7
Create build.yml
ORybak5 9176f7b
update build.xml
ORybak5 669abda
update main branch name
ORybak5 f011e93
Merge branch 'master' into ole4ryb-patch-2
ORybak5 06b75ae
adding a missing jacoco report dependency
ORybak5 5096bca
adding a missing docker logs script
ORybak5 b6551f5
adding missing build id generator script
ORybak5 530317e
Merge branch 'master' into ole4ryb-patch-2
ORybak5 fd6f12e
adding docker build and publish steps
ORybak5 e2a76e6
Merge branch 'ole4ryb-patch-2' of https://github.com/NHSDigital/integ…
ORybak5 5fc696d
role session rename
ORybak5 1f8d8eb
Merge branch 'master' into ole4ryb-patch-2
ORybak5 a38ed6f
Merge branch 'master' into ole4ryb-patch-2
ORybak5 662b700
java version check
ORybak5 6db262f
Merge branch 'ole4ryb-patch-2' of https://github.com/NHSDigital/integ…
ORybak5 5f6f1ee
removing java version check as it is not needed in prod
ORybak5 f2b7ef2
making scripts executable
ORybak5 c689c6f
adding exec permissions before working on the files
ORybak5 4da3026
removing unused GH token
ORybak5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,280 @@ | ||
|
|
||
| name: 111 Adaptor Build Workflow | ||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| branches: | ||
| - master | ||
| push: | ||
| branches: | ||
| - master | ||
|
|
||
| jobs: | ||
| checkstyle: | ||
| name: Checkstyle | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Java 21 LTS | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: 21 | ||
| distribution: 'temurin' | ||
|
|
||
| - name: Checkstyle | ||
| run: | | ||
| ./gradlew checkStyleMain checkstyleTest checkstyleIntegrationTest --parallel | ||
| working-directory: ./service | ||
|
|
||
| - name: Collect Artifacts | ||
| if: always() | ||
| run: | | ||
| mkdir -p artifacts | ||
| cp -r ./service/build/reports ./artifacts | ||
|
|
||
| - name: Upload Artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: 'Checkstyle Reports' | ||
| path: ./artifacts/** | ||
| compression-level: 9 | ||
|
|
||
| - name: Temporary Artifacts Cleanup | ||
| run: rm -rf ./artifacts | ||
|
|
||
| spotbugs: | ||
| name: Spotbugs | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Java 21 LTS | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: 21 | ||
| distribution: 'temurin' | ||
|
|
||
| - name: Spotbugs | ||
| run: | | ||
| ./gradlew spotbugsMain spotbugsTest spotbugsIntegrationTest --parallel | ||
| working-directory: ./service | ||
|
|
||
| - name: Collect Artifacts | ||
| if: always() | ||
| run: | | ||
| mkdir -p artifacts | ||
| cp -r ./service/build/reports ./artifacts | ||
|
|
||
| - name: Upload Artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: 'Spotbugs Reports' | ||
| path: ./artifacts/** | ||
| compression-level: 9 | ||
|
|
||
| - name: Temporary Artifacts Cleanup | ||
| run: rm -rf ./artifacts | ||
|
|
||
| unit-tests: | ||
| name: Unit Tests | ||
| runs-on: ubuntu-latest | ||
| needs: [ checkstyle, spotbugs ] | ||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Setup Java 21 LTS | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: 21 | ||
| distribution: 'temurin' | ||
|
|
||
| - name: Execute Unit Tests | ||
| run: ./gradlew test jacocoTestReport --parallel --build-cache | ||
| working-directory: ./service | ||
|
|
||
| - name: Collect Artifacts | ||
| if: always() | ||
| run: | | ||
| mkdir -p artifacts | ||
| cp -r ./service/build/reports ./artifacts | ||
|
|
||
| - name: Upload Artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: 'Unit Test Reports' | ||
| path: ./artifacts/** | ||
| compression-level: 9 | ||
|
|
||
| - name: Temporary Artifacts Cleanup | ||
| run: rm -rf ./artifacts | ||
|
|
||
| integration-tests: | ||
| name: Integration Tests | ||
| runs-on: ubuntu-latest | ||
| needs: [ checkstyle, spotbugs ] | ||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Java 21 LTS | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: 21 | ||
| distribution: 'temurin' | ||
|
|
||
| - name: Start Docker Dependencies | ||
| env: | ||
| PEM111_AMQP_BROKER: "amqp://activemq:5672" | ||
| PEM111_AMQP_PORT: "5672" | ||
| PEM111_ITK_EXTERNAL_CONFIGURATION_URL: "http://wiremock:8080/configuration/ods-dos" | ||
| LOG_LEVEL: DEBUG | ||
| run: | | ||
| docker network create 111network | ||
| docker compose build | ||
| docker compose up activemq wiremock --detach | ||
| working-directory: ./docker | ||
|
|
||
| - name: Execute Integration Tests | ||
| run: ./gradlew integrationTest | ||
| working-directory: ./service | ||
|
|
||
| - name: Dump Docker Logs | ||
| if: always() | ||
| run: | | ||
| chmod +x dump_docker_logs.sh | ||
| ./dump_docker_logs.sh | ||
ORybak5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| working-directory: ./scripts | ||
| shell: bash | ||
|
|
||
| - name: Collect Artifacts | ||
| if: always() | ||
| run: | | ||
| mkdir -p artifacts | ||
| cp -r ./service/build/reports ./artifacts | ||
| cp -r ./scripts/logs ./artifacts | ||
|
|
||
| - name: Upload Artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: 'Integration Test Reports & Docker Logs' | ||
| path: ./artifacts/** | ||
| compression-level: 9 | ||
|
|
||
| - name: Stop Docker Dependencies | ||
| if: always() | ||
| run: | | ||
| docker compose down --rmi=local --volumes --remove-orphans | ||
| docker compose rm | ||
| docker network rm 111network | ||
| working-directory: ./docker | ||
|
|
||
| - name: Temporary Artifacts Cleanup | ||
| run: rm -rf ./artifacts | ||
|
|
||
| generate-build-id: | ||
| name: Generate Build ID | ||
| runs-on: ubuntu-latest | ||
| needs: [unit-tests, integration-tests] | ||
| outputs: | ||
| build-id: ${{ steps.generate.outputs.buildId }} | ||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - id: generate | ||
| working-directory: ./scripts | ||
| shell: bash | ||
| run: | | ||
| chmod +x ./create_build_id.sh | ||
ORybak5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | ||
| GIT_BRANCH=PR | ||
| elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/master" ]]; then | ||
| GIT_BRANCH=master | ||
| fi | ||
|
|
||
| BUILD_ID=$(./create_build_id.sh $GIT_BRANCH ${{ github.run_number }} ${{ github.sha }}) | ||
| echo "Generated the build tag: $BUILD_ID" | ||
| echo "buildId=$BUILD_ID" >> $GITHUB_OUTPUT | ||
|
|
||
|
|
||
| build-and-publish-docker-images: | ||
| name: Build & Publish Docker Images | ||
| runs-on: ubuntu-latest | ||
| needs: [unit-tests, integration-tests, generate-build-id] | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| strategy: | ||
| matrix: | ||
| config: | ||
| - directory: service | ||
| repository: 111 | ||
| build-context: . | ||
| - directory: nginx | ||
| repository: 111-nginx | ||
| build-context: . | ||
|
|
||
| if: github.actor != 'dependabot[bot]' | ||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Configure AWS Credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_TO_ASSUME }} | ||
| role-session-name: 111_github_action_build_workflow | ||
| aws-region: ${{ secrets.AWS_REGION || 'eu-west-2' }} | ||
|
|
||
| - name: Build Docker Image | ||
| run: | | ||
| # Create Docker Tag | ||
| DOCKER_REGISTRY="${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com" | ||
| DOCKER_TAG="$DOCKER_REGISTRY/${{ matrix.config.repository }}:${{ needs.generate-build-id.outputs.build-id }}" | ||
| echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV | ||
|
|
||
| # Build Image | ||
| docker build -f ./docker/${{ matrix.config.directory }}/Dockerfile -t $DOCKER_TAG ${{ matrix.config.build-context }} | ||
|
|
||
| - name: Login to AWS ECR | ||
| run: | | ||
| DOCKER_REGISTRY="https://${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com" | ||
| aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin $DOCKER_REGISTRY | ||
|
|
||
| - name: Publish image to ECR | ||
| run: docker push $DOCKER_TAG | ||
|
|
||
| - name: Logout of AWS ECR (Clean up Credentials) | ||
| if: always() | ||
| run: | | ||
| DOCKER_REGISTRY="https://${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com" | ||
| docker logout $DOCKER_REGISTRY | ||
|
|
||
| comment: | ||
| if: github.event_name == 'pull_request' | ||
| name: "Create Build ID Comment" | ||
| needs: [generate-build-id] | ||
| continue-on-error: true | ||
| permissions: write-all | ||
| runs-on: [ ubuntu-latest ] | ||
| steps: | ||
| - name: Check out code | ||
| uses: actions/checkout@v4 | ||
| - name: Comment PR | ||
| uses: thollander/actions-comment-pull-request@v3 | ||
| with: | ||
| message: | | ||
| Images built and published to ECR using a Build Id of ${{ needs.generate-build-id.outputs.build-id }} | ||
| comment_tag: images-built | ||
| mode: upsert | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/bin/bash | ||
|
|
||
| clean_tag_element() { | ||
| local tag_element="$1" | ||
| echo "${tag_element//\//-}" | ||
| } | ||
|
|
||
| generate_tag() { | ||
| local clean_branch_name=$(clean_tag_element "$1") | ||
| local clean_build_id=$(clean_tag_element "$2") | ||
| local git_hash="$3" | ||
|
|
||
| local tag="${clean_branch_name}-${clean_build_id}-${git_hash:0:7}" | ||
|
|
||
| echo "$tag" | ||
| } | ||
|
|
||
| if [[ $# -ne 3 ]]; then | ||
| echo "Usage: $0 branch_name build_id git_hash" | ||
| exit 1 | ||
| fi | ||
|
|
||
| branch_name="$1" | ||
| build_id="$2" | ||
| git_hash="$3" | ||
|
|
||
| generate_tag "$branch_name" "$build_id" "$git_hash" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/bin/bash | ||
|
|
||
| mkdir -p ./logs | ||
|
|
||
| container_names=$(docker ps -a --format '{{.Names}}') | ||
|
|
||
| for container in $container_names; do | ||
| docker logs "$container" > ./logs/"$container".log | ||
| echo "Logs saved for container: $container" | ||
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably rename the master branch to main to be consistent with the other repos at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I can do that in a separate PR