Skip to content

Commit 13c390a

Browse files
committed
Separate builder and runner image
1 parent ac745b3 commit 13c390a

File tree

9 files changed

+202
-118
lines changed

9 files changed

+202
-118
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Build docker images
2+
description: Build Docker Images
3+
inputs:
4+
dockerfile:
5+
description: Dockerfile to build
6+
required: true
7+
tags:
8+
description: Docker tags to publish
9+
required: true
10+
platforms:
11+
description: Platforms to build (csv)
12+
required: false
13+
default: 'linux/arm64,linux/amd64'
14+
test:
15+
description: Test command to run on the created image (Optional)
16+
required: false
17+
default: ''
18+
build-args:
19+
description: Explicit docker build-args
20+
required: false
21+
default: ''
22+
skip-init:
23+
description: Skip docker init (if ran after another invocation of this action)
24+
required: false
25+
default: ''
26+
docker-user:
27+
required: true
28+
description: Docker Hub User
29+
docker-password:
30+
required: true
31+
description: Docker Hub User
32+
skip-push:
33+
required: false
34+
description: Optionally skip push
35+
default: ''
36+
load-created-image:
37+
required: false
38+
description: Optionally load created docker image
39+
default: ''
40+
41+
runs:
42+
using: 'composite'
43+
steps:
44+
# - name: Setup docker (missing on MacOS)
45+
# if: matrix.platform == 'linux/arm64'
46+
# uses: douglascamata/setup-docker-macos-action@v1-alpha
47+
48+
- name: Set up QEMU
49+
uses: docker/setup-qemu-action@v3
50+
if: ${{ inputs.skip-init == '' }}
51+
52+
- name: Set up Docker Buildx
53+
uses: docker/setup-buildx-action@v3
54+
if: ${{ inputs.skip-init == '' }}
55+
56+
- name: Login to Docker Hub
57+
uses: docker/login-action@v3
58+
if: ${{ inputs.skip-init == '' }}
59+
with:
60+
registry: ghcr.io
61+
username: ${{ inputs.docker-user }}
62+
password: ${{ inputs.docker-password }}
63+
64+
- name: Build Runner Image
65+
uses: docker/build-push-action@v6
66+
with:
67+
context: .
68+
file: ${{ inputs.dockerfile }}
69+
platforms: ${{ inputs.platforms }}
70+
push: ${{ inputs.skip-push == '' }}
71+
load: ${{ inputs.test != '' || inputs.load-created-image != '' }}
72+
tags: ${{ inputs.tags }}
73+
build-args: |
74+
${{ inputs.build-args }}
75+
76+
- name: Verify Built Image
77+
shell: bash
78+
if: ${{ inputs.test != '' }}
79+
run: |
80+
SINGLE_TAG=$(echo "${{ inputs.tags }}" | awk -F ',' '{print $1};' )
81+
SINGLE_PLATFORM=$(echo "${{ inputs.platforms }}" | awk -F ',' '{print $1};' )
82+
docker run --platform "${SINGLE_PLATFORM}" --rm --entrypoint bash "${SINGLE_TAG}" -c '${{ inputs.test }}'

.github/workflows/ci.yml

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: Build integration images
22
on:
33
pull_request:
4-
workflow_dispatch:
54

65
jobs:
76
prepare-matrix:
@@ -39,7 +38,6 @@ jobs:
3938
4039
4140
build-integration:
42-
# runs-on: ${{ matrix.platform == 'linux/arm64' && 'macos-13' || 'ubuntu-latest' }}
4341
runs-on: 'ubuntu-latest'
4442
if: needs.prepare-matrix.outputs.matrix != '[]'
4543
outputs:
@@ -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
93+
- name: Build Docker Image
94+
uses: ./.github/workflows/actions/build-docker-image
11695
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
128-
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: 'yupp'

.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 & 28 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,13 +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
8781

8882
- name: Extract version and image tag
8983
id: enrich-version
@@ -97,17 +91,16 @@ jobs:
9791
echo "identifier=${IDENTIFIER}" >> ${GITHUB_OUTPUT}
9892
echo "image_tag=${IMAGE_FULL_TAG}" >> ${GITHUB_OUTPUT}
9993
100-
- name: Build
101-
uses: docker/build-push-action@v6
94+
- name: Build Docker Image
95+
uses: ./.github/workflows/actions/build-docker-image
10296
with:
103-
context: .
104-
file: ./integrations/_infra/Dockerfile
97+
dockerfile: ./integrations/_infra/Dockerfile
10598
platforms: linux/amd64
106-
push: false
99+
skip-push: 'yupp'
107100
tags: ${{ steps.enrich-version.outputs.image_tag }}
108-
load: true
109-
cache-from: type=gha
110-
cache-to: type=gha,mode=max
101+
load-created-image: 'yupp'
102+
docker-user: ${{ secrets.DOCKER_MACHINE_USER }}
103+
docker-password: ${{ secrets.DOCKER_MACHINE_TOKEN }}
111104
build-args: |
112105
BUILD_CONTEXT=./integrations/${{ steps.enrich-version.outputs.integration }}
113106
INTEGRATION_VERSION=${{ steps.enrich-version.outputs.version }}

.github/workflows/infra.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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: ${{ matrix.platform == 'linux/arm64' && 'macos-13' || 'ubuntu-latest' }}
11+
runs-on: 'ubuntu-latest'
12+
needs: detect-changes
13+
if: ${{ needs.detect-changes.outputs.infra == 'true' }}
14+
steps:
15+
- name: Check out code
16+
uses: actions/checkout@v4
17+
18+
- name: Build Docker Image
19+
uses: ./.github/workflows/actions/build-docker-image
20+
with:
21+
dockerfile: ./integrations/_infra/Dockerfile.base.builder
22+
platforms: linux/amd64,linux/arm64
23+
tags: ghcr.io/port-labs/port-ocean-base-builder:latest
24+
docker-user: ${{ secrets.DOCKER_MACHINE_USER }}
25+
docker-password: ${{ secrets.DOCKER_MACHINE_TOKEN }}
26+
27+
28+
- name: Build Docker Image
29+
uses: ./.github/workflows/actions/build-docker-image
30+
with:
31+
dockerfile: ./integrations/_infra/Dockerfile.base.runner
32+
platforms: linux/amd64,linux/arm64
33+
tags: ghcr.io/port-labs/port-ocean-base-runner:latest
34+
docker-user: ${{ secrets.DOCKER_MACHINE_USER }}
35+
docker-password: ${{ secrets.DOCKER_MACHINE_TOKEN }}
36+
skip-init: 'yupp'

.github/workflows/release-integrations.yml

Lines changed: 7 additions & 23 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: |
@@ -63,18 +58,7 @@ jobs:
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)