From 0ae559c31bf650fa47674cc64f1d98f25bbbf2a7 Mon Sep 17 00:00:00 2001 From: edinstance Date: Mon, 20 Oct 2025 17:36:25 +0100 Subject: [PATCH 1/7] feat: created action to build docker images --- .github/workflows/build_images.yml | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/build_images.yml diff --git a/.github/workflows/build_images.yml b/.github/workflows/build_images.yml new file mode 100644 index 0000000..bf5c99b --- /dev/null +++ b/.github/workflows/build_images.yml @@ -0,0 +1,51 @@ +name: Build Images + +on: + pull_request: + types: [ closed ] + branches: + - main + - dev + - test + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.base.ref }} + cancel-in-progress: true + +env: + REGISTRY: ghcr.io + IMAGE_PREFIX: ghcr.io/${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + service: [ + "services/flights", + "services/aircraft", + "services/search", + "services/authentication", + "services/gateway" + ] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push image + uses: docker/build-push-action@v6 + with: + context: ./${{ matrix.service }} + file: ./${{ matrix.service }}/Dockerfile + push: true + tags: | + ${{ env.IMAGE_PREFIX }}-${{ matrix.service }}:${{ github.sha }} + ${{ github.event.pull_request.base.ref == 'main' && format('{0}-{1}:latest', env.IMAGE_PREFIX, matrix.service) || '' }} \ No newline at end of file From e5d8682124a32a6419f2c73e63ab991687ff0786 Mon Sep 17 00:00:00 2001 From: edinstance Date: Mon, 20 Oct 2025 17:42:34 +0100 Subject: [PATCH 2/7] feat: added branch rules and workflow dispatch --- .github/workflows/build_images.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_images.yml b/.github/workflows/build_images.yml index bf5c99b..f12ef77 100644 --- a/.github/workflows/build_images.yml +++ b/.github/workflows/build_images.yml @@ -1,6 +1,7 @@ name: Build Images on: + workflow_dispatch: pull_request: types: [ closed ] branches: From 35003ed98d00b0f7d04f52226a9ae8a3c330340f Mon Sep 17 00:00:00 2001 From: edinstance Date: Mon, 20 Oct 2025 17:43:55 +0100 Subject: [PATCH 3/7] fix: added pr protection so workflow doesnt run on closed prs --- .github/workflows/build_images.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build_images.yml b/.github/workflows/build_images.yml index f12ef77..1562cd3 100644 --- a/.github/workflows/build_images.yml +++ b/.github/workflows/build_images.yml @@ -20,6 +20,10 @@ env: jobs: build: runs-on: ubuntu-latest + if: | + (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || + (github.event_name == 'workflow_dispatch') + strategy: matrix: service: [ From 48e838b9f975ed2a576cdd54aec23ce8417b3d6e Mon Sep 17 00:00:00 2001 From: edinstance Date: Mon, 20 Oct 2025 17:44:42 +0100 Subject: [PATCH 4/7] fix: fixed branch checks --- .github/workflows/build_images.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_images.yml b/.github/workflows/build_images.yml index 1562cd3..3b5e811 100644 --- a/.github/workflows/build_images.yml +++ b/.github/workflows/build_images.yml @@ -53,4 +53,4 @@ jobs: push: true tags: | ${{ env.IMAGE_PREFIX }}-${{ matrix.service }}:${{ github.sha }} - ${{ github.event.pull_request.base.ref == 'main' && format('{0}-{1}:latest', env.IMAGE_PREFIX, matrix.service) || '' }} \ No newline at end of file + ${{ github.ref_name == 'main' && format('{0}-{1}:latest', env.IMAGE_PREFIX, matrix.service) || '' }} \ No newline at end of file From d56f59c2682c51fa281f2f0ee7e37042ab0391c1 Mon Sep 17 00:00:00 2001 From: edinstance Date: Mon, 20 Oct 2025 18:09:14 +0100 Subject: [PATCH 5/7] feat: added service deps to build images --- .github/workflows/build_images.yml | 37 ++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build_images.yml b/.github/workflows/build_images.yml index 3b5e811..4fe69f7 100644 --- a/.github/workflows/build_images.yml +++ b/.github/workflows/build_images.yml @@ -26,18 +26,41 @@ jobs: strategy: matrix: - service: [ - "services/flights", - "services/aircraft", - "services/search", - "services/authentication", - "services/gateway" - ] + include: + - service: services/flights + uses_buf: true + - service: services/aircraft + uses_buf: true + needs_app_file: true + - service: services/search + needs_app_file: true + uses_buf: false + - service: services/authentication + uses_buf: false + - service: services/gateway + uses_buf: false steps: + # Checkout code - name: Checkout repository uses: actions/checkout@v4 + # Setup the service dependencies + - name: Install buf + if: matrix.uses_buf + uses: bufbuild/buf-setup-action@v1.50.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Build proto files + if: matrix.uses_buf + run: buf generate --template buf.gen.yaml + + - name: Create aircraft application file + if: matrix.needs_app_file + run: cp services/aircraft/src/main/resources/prod-application.example.yml services/aircraft/src/main/resources/application.yml + + # Build and push the image to GitHub Container Registry - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: From 948d4e21d3f50b3d1123b4ac6883e9b884f3adaa Mon Sep 17 00:00:00 2001 From: edinstance Date: Mon, 20 Oct 2025 18:23:07 +0100 Subject: [PATCH 6/7] fix: make application file service aware --- .github/workflows/build_images.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_images.yml b/.github/workflows/build_images.yml index 4fe69f7..1348ad0 100644 --- a/.github/workflows/build_images.yml +++ b/.github/workflows/build_images.yml @@ -56,9 +56,9 @@ jobs: if: matrix.uses_buf run: buf generate --template buf.gen.yaml - - name: Create aircraft application file + - name: Create application file if: matrix.needs_app_file - run: cp services/aircraft/src/main/resources/prod-application.example.yml services/aircraft/src/main/resources/application.yml + run: cp ${{ matrix.service }}/src/main/resources/prod-application.example.yml ${{ matrix.service }}/src/main/resources/application.yml # Build and push the image to GitHub Container Registry - name: Log in to GitHub Container Registry From 8ba29223949e5af3fcfff3104aaada08613d133c Mon Sep 17 00:00:00 2001 From: Edward Instance Date: Mon, 20 Oct 2025 18:42:36 +0100 Subject: [PATCH 7/7] fix: updated image prefix --- .github/workflows/build_images.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_images.yml b/.github/workflows/build_images.yml index 1348ad0..8c65917 100644 --- a/.github/workflows/build_images.yml +++ b/.github/workflows/build_images.yml @@ -15,7 +15,7 @@ concurrency: env: REGISTRY: ghcr.io - IMAGE_PREFIX: ghcr.io/${{ github.repository }} + IMAGE_PREFIX: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }} jobs: build: @@ -76,4 +76,4 @@ jobs: push: true tags: | ${{ env.IMAGE_PREFIX }}-${{ matrix.service }}:${{ github.sha }} - ${{ github.ref_name == 'main' && format('{0}-{1}:latest', env.IMAGE_PREFIX, matrix.service) || '' }} \ No newline at end of file + ${{ github.ref_name == 'main' && format('{0}-{1}:latest', env.IMAGE_PREFIX, matrix.service) || '' }}