Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit 7c132d5

Browse files
committed
chore: added multistage using a builder with node modules cached.
This commit introduces 2 Containerfiles: 1 for build a base image acting as node modules cache and 2 a multistage build which uses the builder to reduce the required traffic to download modules on each build. Also it includes the gh actions required to build both images: builder and extension during development (all images will be pushed to ghcr) Signed-off-by: Adrian Riobo <[email protected]>
1 parent 94e3f06 commit 7c132d5

File tree

6 files changed

+258
-20
lines changed

6 files changed

+258
-20
lines changed

.github/workflows/build-builder.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
# Copyright (C) 2025 Red Hat, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# SPDX-License-Identifier: Apache-2.0
17+
18+
name: build-builder
19+
20+
on:
21+
push:
22+
branches:
23+
- main
24+
25+
jobs:
26+
build-and-push-image:
27+
runs-on: ubuntu-24.04
28+
permissions:
29+
contents: read
30+
packages: write
31+
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
35+
36+
- name: Build Image
37+
id: build-image
38+
uses: redhat-actions/buildah-build@7a95fa7ee0f02d552a32753e7414641a04307056 #v2.13
39+
with:
40+
image: ghcr.io/${{ github.repository }}-builder
41+
tags: latest ${{ github.sha }}
42+
containerfiles: |
43+
./oci/Containerfile.builder
44+
45+
- name: Push To Registry
46+
uses: redhat-actions/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c #v2.8
47+
with:
48+
image: ${{ steps.build-image.outputs.image }}
49+
tags: ${{ steps.build-image.outputs.tags }}
50+
registry: ghcr.io
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#
2+
# Copyright (C) 2025 Red Hat, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# SPDX-License-Identifier: Apache-2.0
17+
18+
name: build-extension
19+
20+
on:
21+
push:
22+
branches: [ main ]
23+
pull_request:
24+
branches: [ main ]
25+
26+
jobs:
27+
build:
28+
name: build
29+
runs-on: ubuntu-24.04
30+
env:
31+
VERSION: "latest"
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
35+
36+
- name: Set extension image name
37+
if: github.event_name == 'pull_request'
38+
run: echo "VERSION=pr-${{ github.event.number }}" >> $GITHUB_ENV
39+
40+
- name: Build extension
41+
env:
42+
IMG: ghcr.io/crc-org/podman-desktop-extension-macadam:${VERSION}
43+
shell: bash
44+
run: |
45+
podman build -t ${IMG} -f oci/Containerfile.multistage .
46+
podman save -m -o podman-desktop-extension-macadam.tar ${IMG}
47+
echo ${IMG} > podman-desktop-extension-macadam.image
48+
49+
- name: Upload extension oci flatten images
50+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
51+
with:
52+
name: podman-desktop-extension-macadam
53+
path: podman-desktop-extension-macadam*
54+
55+
push:
56+
name: push
57+
if: github.event_name == 'push'
58+
needs: build
59+
runs-on: ubuntu-24.04
60+
permissions:
61+
contents: read
62+
packages: write
63+
steps:
64+
- name: Download extension oci flatten images
65+
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
66+
with:
67+
name: podman-desktop-extension-macadam
68+
69+
- name: Log in to ghcr.io
70+
uses: redhat-actions/podman-login@4934294ad0449894bcd1e9f191899d7292469603 # v1.7
71+
with:
72+
registry: ghcr.io
73+
username: ${{ github.actor }}
74+
password: ${{ secrets.GITHUB_TOKEN }}
75+
76+
- name: Push image for Release
77+
shell: bash
78+
run: |
79+
podman load -i podman-desktop-extension-macadam.tar
80+
podman push ghcr.io/crc-org/podman-desktop-extension-macadam:latest
81+
82+
83+
84+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#
2+
# Copyright (C) 2025 Red Hat, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# SPDX-License-Identifier: Apache-2.0
17+
18+
name: push-extension-pr
19+
20+
on:
21+
workflow_run:
22+
workflows:
23+
- build-extension
24+
types:
25+
- completed
26+
27+
jobs:
28+
push:
29+
name: push
30+
if: |
31+
github.event.workflow_run.conclusion == 'success' &&
32+
github.event.workflow_run.event == 'pull_request'
33+
runs-on: ubuntu-24.04
34+
permissions:
35+
contents: read
36+
packages: write
37+
steps:
38+
- name: Download extension oci flatten images
39+
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
40+
with:
41+
name: podman-desktop-extension-macadam
42+
run-id: ${{ github.event.workflow_run.id }}
43+
github-token: ${{ github.token }}
44+
45+
- name: Get image
46+
shell: bash
47+
run: |
48+
echo "IMAGE=$(cat podman-desktop-extension-macadam.image)" >> "$GITHUB_ENV"
49+
50+
- name: Log in to ghcr.io
51+
uses: redhat-actions/podman-login@4934294ad0449894bcd1e9f191899d7292469603 # v1.7
52+
with:
53+
registry: ghcr.io
54+
username: ${{ github.actor }}
55+
password: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Push image for Release
58+
shell: bash
59+
run: |
60+
podman load -i podman-desktop-extension-macadam.tar
61+
podman push ${IMAGE}

Containerfile

Lines changed: 0 additions & 20 deletions
This file was deleted.

oci/Containerfile.builder

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Copyright (C) 2025 Red Hat, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# SPDX-License-Identifier: Apache-2.0
17+
18+
FROM registry.access.redhat.com/ubi9/nodejs-20
19+
20+
COPY package.json .
21+
22+
RUN npm i -g ssh2@1.16.0 \
23+
&& npm install yarn --global \
24+
&& yarn --frozen-lockfile --network-timeout 180000

oci/Containerfile.multistage

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# Copyright (C) 2025 Red Hat, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# SPDX-License-Identifier: Apache-2.0
17+
18+
FROM ghcr.io/crc-org/podman-desktop-extension-macadam-builder:latest AS builder
19+
20+
COPY . .
21+
22+
RUN yarn --network-timeout 180000 \
23+
&& yarn build
24+
25+
FROM scratch
26+
27+
LABEL org.opencontainers.image.title="Macadam extension" \
28+
org.opencontainers.image.description="Example of Macadam extension" \
29+
org.opencontainers.image.vendor="podman-desktop" \
30+
io.podman-desktop.api.version=">= 1.10.0"
31+
32+
COPY package.json /extension/
33+
COPY LICENSE /extension/
34+
COPY icon.png /extension/
35+
COPY README.md /extension/
36+
COPY --from=builder /opt/app-root/src/dist /extension/dist
37+
COPY --from=builder /opt/app-root/src/node_modules/ssh2/ /extension/node_modules/ssh2

0 commit comments

Comments
 (0)