Skip to content

Commit 95003b9

Browse files
committed
Separate builder and runner image
1 parent b187df3 commit 95003b9

File tree

9 files changed

+203
-121
lines changed

9 files changed

+203
-121
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Build docker images
2+
description: Build Docker Images
3+
# NOTE: In composite actions, all parameters are strings,
4+
# thus flags are simply checked by being non empty strings,
5+
# where there the default is an empty string
6+
inputs:
7+
dockerfile:
8+
description: Dockerfile to build
9+
required: true
10+
tags:
11+
description: Docker tags to publish
12+
required: true
13+
platforms:
14+
description: Platforms to build (csv)
15+
required: false
16+
default: 'linux/arm64,linux/amd64'
17+
test:
18+
description: Test command to run on the created image (Optional)
19+
required: false
20+
default: ''
21+
build-args:
22+
description: Explicit docker build-args
23+
required: false
24+
default: ''
25+
skip-init:
26+
description: Skip docker init (if ran after another invocation of this action)
27+
required: false
28+
default: ''
29+
docker-user:
30+
required: true
31+
description: Docker Hub User
32+
docker-password:
33+
required: true
34+
description: Docker Hub User
35+
skip-push:
36+
required: false
37+
description: Optionally skip push
38+
default: ''
39+
load-created-image:
40+
required: false
41+
description: Optionally load created docker image
42+
default: ''
43+
44+
runs:
45+
using: 'composite'
46+
steps:
47+
- name: Set up QEMU
48+
uses: docker/setup-qemu-action@v3
49+
if: ${{ inputs.skip-init == '' }}
50+
51+
- name: Set up Docker Buildx
52+
uses: docker/setup-buildx-action@v3
53+
if: ${{ inputs.skip-init == '' }}
54+
55+
- name: Login to Docker Hub
56+
uses: docker/login-action@v3
57+
if: ${{ inputs.skip-init == '' }}
58+
with:
59+
registry: ghcr.io
60+
username: ${{ inputs.docker-user }}
61+
password: ${{ inputs.docker-password }}
62+
63+
- name: Build Runner Image
64+
uses: docker/build-push-action@v6
65+
with:
66+
context: .
67+
file: ${{ inputs.dockerfile }}
68+
platforms: ${{ inputs.platforms }}
69+
push: ${{ inputs.skip-push == '' }}
70+
load: ${{ inputs.test != '' || inputs.load-created-image != '' }}
71+
tags: ${{ inputs.tags }}
72+
build-args: |
73+
${{ inputs.build-args }}
74+
75+
- name: Verify Built Image
76+
shell: bash
77+
if: ${{ inputs.test != '' }}
78+
run: |
79+
SINGLE_TAG=$(echo "${{ inputs.tags }}" | awk -F ',' '{print $1};' )
80+
SINGLE_PLATFORM=$(echo "${{ inputs.platforms }}" | awk -F ',' '{print $1};' )
81+
docker run --platform "${SINGLE_PLATFORM}" --rm --entrypoint bash "${SINGLE_TAG}" -c '${{ inputs.test }}'
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Build infra images
2+
on:
3+
pull_request:
4+
workflow_dispatch:
5+
6+
jobs:
7+
detect-changes:
8+
uses: ./.github/workflows/detect-changes-matrix.yml
9+
build-infra:
10+
runs-on: 'ubuntu-latest'
11+
needs: detect-changes
12+
if: ${{ needs.detect-changes.outputs.infra == 'true' }}
13+
steps:
14+
- name: Check out code
15+
uses: actions/checkout@v4
16+
17+
- name: Build Docker Image
18+
uses: ./.github/workflows/actions/build-docker-image
19+
with:
20+
dockerfile: ./integrations/_infra/Dockerfile.base.builder
21+
platforms: linux/amd64,linux/arm64
22+
tags: ghcr.io/port-labs/port-ocean-base-builder:latest
23+
docker-user: ${{ secrets.DOCKER_MACHINE_USER }}
24+
docker-password: ${{ secrets.DOCKER_MACHINE_TOKEN }}
25+
26+
- name: Build Docker Image
27+
uses: ./.github/workflows/actions/build-docker-image
28+
with:
29+
dockerfile: ./integrations/_infra/Dockerfile.base.runner
30+
platforms: linux/amd64,linux/arm64
31+
tags: ghcr.io/port-labs/port-ocean-base-runner:latest
32+
docker-user: ${{ secrets.DOCKER_MACHINE_USER }}
33+
docker-password: ${{ secrets.DOCKER_MACHINE_TOKEN }}
34+
skip-init: 'true'

.github/workflows/ci.yml

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ jobs:
3737
echo $(echo ${integrations_to_build[@]} | jq -R -c 'split(" ")')
3838
echo "INTEGRATIONS_MATRIX=$(echo ${integrations_to_build[@]} | jq -R -c 'split(" ")')" >> $GITHUB_OUTPUT
3939
40-
4140
build-integration:
42-
# runs-on: ${{ matrix.platform == 'linux/arm64' && 'macos-13' || 'ubuntu-latest' }}
43-
runs-on: 'ubuntu-latest'
41+
runs-on: ubuntu-latest
4442
if: needs.prepare-matrix.outputs.matrix != '[]'
4543
outputs:
4644
is_dev_version: ${{ steps.prepare_tags.outputs.is_dev_version }}
@@ -58,20 +56,6 @@ jobs:
5856
- name: Check out code
5957
uses: actions/checkout@v4
6058

61-
# - name: Setup docker (missing on MacOS)
62-
# if: matrix.platform == 'linux/arm64'
63-
# uses: douglascamata/setup-docker-macos-action@v1-alpha
64-
65-
- name: Set up QEMU
66-
uses: docker/setup-qemu-action@v3
67-
with:
68-
platforms: ${{ matrix.platform }}
69-
70-
- name: Set up Docker Buildx
71-
uses: docker/setup-buildx-action@v3
72-
with:
73-
platforms: ${{ matrix.platform }}
74-
7559
- name: Prepare Docker images tags
7660
id: prepare_tags
7761
run: |
@@ -106,37 +90,15 @@ jobs:
10690
echo "is_dev_version=false" >> $GITHUB_OUTPUT
10791
fi
10892
109-
- name: Get used docker base image
110-
id: get-docker-image
111-
run: |
112-
echo "base_image=$(cat ${{ steps.prepare_tags.outputs.dockerfile_path }} | head -n 1 | awk -F '=' '{print $2}' )" >> $GITHUB_OUTPUT
113-
114-
- name: Login to Docker Hub
115-
uses: docker/login-action@v3
116-
with:
117-
registry: ghcr.io
118-
username: ${{ secrets.DOCKER_MACHINE_USER }}
119-
password: ${{ secrets.DOCKER_MACHINE_TOKEN }}
120-
121-
# - name: Cache Docker images
122-
# uses: ScribeMD/docker-cache@0.5.0
123-
# with:
124-
# key: docker-${{ matrix.integration }}-${{ steps.get-docker-image.outputs.base_image }}-${{ matrix.platform }}
125-
126-
- name: Build
127-
uses: docker/build-push-action@v6
93+
- name: Build Docker Image
94+
uses: ./.github/workflows/actions/build-docker-image
12895
with:
129-
context: .
130-
file: ${{ steps.prepare_tags.outputs.dockerfile_path }}
96+
dockerfile: ${{ steps.prepare_tags.outputs.dockerfile_path }}
13197
platforms: ${{ matrix.platform }}
132-
push: false
133-
load: true
13498
tags: ${{ steps.prepare_tags.outputs.tags }}
13599
build-args: |
136100
BUILD_CONTEXT=${{ steps.prepare_tags.outputs.context_dir }}
137101
INTEGRATION_VERSION=${{ steps.prepare_tags.outputs.version }}
138-
139-
- name: Verify Built Image
140-
run: |
141-
SINGLE_TAG=$(echo "${{ steps.prepare_tags.outputs.tags }}" | awk -F ',' '{print $1};' )
142-
docker run --platform ${{ matrix.platform }} --rm --entrypoint bash "${SINGLE_TAG}" -c 'ocean version'
102+
docker-user: ${{ secrets.DOCKER_MACHINE_USER }}
103+
docker-password: ${{ secrets.DOCKER_MACHINE_TOKEN }}
104+
skip-push: 'true'

.github/workflows/detect-changes-matrix.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
core:
1212
value: ${{ jobs.detect-changes.outputs.core }}
1313
description: "Determine if any core changes per git commit changes"
14+
infra:
15+
value: ${{ jobs.detect-changes.outputs.infra }}
16+
description: "Determine if any changes to docker infra"
1417

1518
jobs:
1619
detect-changes:
@@ -20,6 +23,7 @@ jobs:
2023
matrix: ${{ steps.set-all-matrix.outputs.matrix }}
2124
integrations: ${{ steps.set-all-matrix.outputs.integrations }}
2225
core: ${{ steps.set-all-matrix.outputs.core }}
26+
infra: ${{ steps.set-all-matrix.outputs.infra}}
2327
steps:
2428
- name: Checkout Repo
2529
uses: actions/checkout@v4
@@ -42,6 +46,8 @@ jobs:
4246
- 'integrations/**'
4347
- '!integrations/**/*.md'
4448
- '!integrations/_infra/*'
49+
infra:
50+
- 'integrations/_infra/*'
4551
4652
- name: Set integrations and all matrix
4753
id: set-all-matrix
@@ -50,8 +56,11 @@ jobs:
5056
HAS_CORE=${{ steps.changed-files.outputs.core_all_changed_files != '[]' }}
5157
echo "Core changes : ${HAS_CORE}"
5258
MATRIX=$(node -e "integrations=${INTEGRATIONS}; hasCore=${HAS_CORE}; console.log(JSON.stringify(hasCore ? integrations.concat(['.']) : integrations))")
59+
HAS_INFRA=${{ steps.changed-files.outputs.infra_all_changed_files != '[]' }}
60+
echo "Infra changes : ${HAS_INFRA}"
5361
echo "Integration changes : ${INTEGRATIONS}"
5462
echo "All changes : ${MATRIX}"
5563
echo "core=${HAS_CORE}" >> $GITHUB_OUTPUT
5664
echo "integrations=${INTEGRATIONS}" >> $GITHUB_OUTPUT
5765
echo "matrix=${MATRIX}" >> $GITHUB_OUTPUT
66+
echo "infra=${HAS_INFRA}" >> $GITHUB_OUTPUT

.github/workflows/docker-images-security-scan.yml

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,34 @@ on:
88
# This is a bit annoying, there's no real way to display the integrations dynamically in a dropdown for the action dispatcher
99
options:
1010
- all
11+
- argocd
1112
- aws
13+
- azure
1214
- azure-devops
15+
- backstage
16+
- datadog
1317
- dynatrace
1418
- fake-integration
15-
- gcp
16-
- jenkins
17-
- kafka
18-
- launchdarkly
19-
- newrelic
20-
- opencost
21-
- pagerduty
22-
- servicenow
23-
- sonarqube
24-
- terraform-cloud
25-
- argocd
26-
- azure
27-
- datadog
2819
- firehydrant
20+
- gcp
2921
- gitlab
22+
- jenkins
3023
- jira
24+
- kafka
3125
- kubecost
26+
- launchdarkly
3227
- linear
28+
- newrelic
3329
- octopus
30+
- opencost
3431
- opsgenie
32+
- pagerduty
3533
- sentry
34+
- servicenow
3635
- snyk
36+
- sonarqube
3737
- statuspage
38+
- terraform-cloud
3839
- wiz
3940

4041
jobs:
@@ -77,14 +78,6 @@ jobs:
7778
- name: Checkout Repo
7879
uses: actions/checkout@v4
7980

80-
- name: Set up QEMU
81-
uses: docker/setup-qemu-action@v3
82-
with:
83-
platforms: linux/amd64,linux/arm64
84-
85-
- name: Set up Docker Buildx
86-
uses: docker/setup-buildx-action@v3
87-
8881
- name: Extract version and image tag
8982
id: enrich-version
9083
run: |
@@ -97,17 +90,16 @@ jobs:
9790
echo "identifier=${IDENTIFIER}" >> ${GITHUB_OUTPUT}
9891
echo "image_tag=${IMAGE_FULL_TAG}" >> ${GITHUB_OUTPUT}
9992
100-
- name: Build
101-
uses: docker/build-push-action@v6
93+
- name: Build Docker Image
94+
uses: ./.github/workflows/actions/build-docker-image
10295
with:
103-
context: .
104-
file: ./integrations/_infra/Dockerfile
96+
dockerfile: ./integrations/_infra/Dockerfile
10597
platforms: linux/amd64
106-
push: false
98+
skip-push: 'true'
10799
tags: ${{ steps.enrich-version.outputs.image_tag }}
108-
load: true
109-
cache-from: type=gha
110-
cache-to: type=gha,mode=max
100+
load-created-image: 'true'
101+
docker-user: ${{ secrets.DOCKER_MACHINE_USER }}
102+
docker-password: ${{ secrets.DOCKER_MACHINE_TOKEN }}
111103
build-args: |
112104
BUILD_CONTEXT=./integrations/${{ steps.enrich-version.outputs.integration }}
113105
INTEGRATION_VERSION=${{ steps.enrich-version.outputs.version }}

.github/workflows/release-integrations.yml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ jobs:
1313
steps:
1414
- name: Check out code
1515
uses: actions/checkout@v4
16-
- name: Login to Docker Hub
17-
uses: docker/login-action@v3
18-
with:
19-
registry: ghcr.io
20-
username: ${{ secrets.DOCKER_MACHINE_USER }}
21-
password: ${{ secrets.DOCKER_MACHINE_TOKEN }}
16+
2217
- name: Prepare matrix
2318
id: prepare-matrix
2419
run: |
@@ -57,24 +52,13 @@ jobs:
5752
needs: [prepare-matrix]
5853
strategy:
5954
# limit the number of parallel jobs to avoid hitting the ghcr.io rate limit
60-
max-parallel: 10
55+
max-parallel: 5
6156
matrix:
6257
integration: ${{fromJson(needs.prepare-matrix.outputs.matrix)}}
6358
steps:
6459
- name: Check out code
6560
uses: actions/checkout@v4
66-
- name: Set up QEMU
67-
uses: docker/setup-qemu-action@v3
68-
with:
69-
platforms: linux/amd64,linux/arm64
70-
- name: Set up Docker Buildx
71-
uses: docker/setup-buildx-action@v3
72-
- name: Login to Docker Hub
73-
uses: docker/login-action@v3
74-
with:
75-
registry: ghcr.io
76-
username: ${{ secrets.DOCKER_MACHINE_USER }}
77-
password: ${{ secrets.DOCKER_MACHINE_TOKEN }}
61+
7862
- name: Prepare Docker images tags
7963
id: prepare_tags
8064
run: |
@@ -108,17 +92,17 @@ jobs:
10892
echo "is_dev_version=false" >> $GITHUB_OUTPUT
10993
fi
11094
111-
- name: Build and push
112-
uses: docker/build-push-action@v6
95+
- name: Build Docker Image
96+
uses: ./.github/workflows/actions/build-docker-image
11397
with:
114-
context: .
115-
file: ${{ steps.prepare_tags.outputs.dockerfile_path }}
98+
dockerfile: ${{ steps.prepare_tags.outputs.dockerfile_path }}
11699
platforms: linux/amd64,linux/arm64
117-
push: true
118100
tags: ${{ steps.prepare_tags.outputs.tags }}
119101
build-args: |
120102
BUILD_CONTEXT=${{ steps.prepare_tags.outputs.context_dir }}
121103
INTEGRATION_VERSION=${{ steps.prepare_tags.outputs.version }}
104+
docker-user: ${{ secrets.DOCKER_MACHINE_USER }}
105+
docker-password: ${{ secrets.DOCKER_MACHINE_TOKEN }}
122106

123107
upload-specs:
124108
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)