Skip to content

Commit a44cc9d

Browse files
authored
feat: allow selection of platforms to build the custom flavor on (#6950)
* feat: allow selection of platforms to build the custom flavor on * [MegaLinter] Apply linters fixes --------- Co-authored-by: bdovaz <[email protected]>
1 parent 13f9ce9 commit a44cc9d

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

.automation/build.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3976,13 +3976,16 @@ def build_custom_flavor(dockerfile):
39763976
work_dir = (
39773977
"/megalinter-builder" if os.path.isdir("/megalinter-builder") else REPO_HOME
39783978
)
3979+
platform = os.getenv("CUSTOM_FLAVOR_PLATFORM", "linux/amd64")
39793980
tag_id = os.getenv("CUSTOM_FLAVOR_BUILD_REPO", "megalinter-custom").replace(
39803981
"/", "_"
39813982
)
39823983
command = [
39833984
"docker",
39843985
"buildx",
39853986
"build",
3987+
"--platform",
3988+
platform,
39863989
"-t",
39873990
tag_id,
39883991
"-f",
@@ -3991,6 +3994,7 @@ def build_custom_flavor(dockerfile):
39913994
"id=GITHUB_TOKEN",
39923995
work_dir,
39933996
]
3997+
logging.info("Platforms to build on: " + platform)
39943998
logging.info("Running command: " + " ".join(command))
39953999
process = subprocess.run(
39964000
command,

docs/custom-flavors.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ You can easily generate your own MegaLinter custom flavor using the `mega-linter
1818

1919
- Create a new GitHub public repository whose name starts with `megalinter-custom-flavor` (example: `megalinter-custom-flavor-npm-groovy-lint`), with default README checked.
2020

21-
![](assets/images/custom-flavor-new-repo.png)
21+
![GitHub form to create a repository](assets/images/custom-flavor-new-repo.png)
2222

2323
### Clone your new repository locally
2424

@@ -35,7 +35,7 @@ npx mega-linter-runner@beta --custom-flavor-setup
3535

3636
You can also send the list of linters as parameters, available from the logs of any official MegaLinter flavor (if you don't see it, make sure `FLAVOR_SUGGESTIONS: true` is defined in your `.mega-linter.yml` config file).
3737

38-
![](assets/images/custom-flavor-command.png)
38+
![Example command to generate the custom flavor](assets/images/custom-flavor-command.png)
3939

4040
```bash
4141
npx mega-linter-runner@beta --custom-flavor-setup --custom-flavor-linters "PYTHON_BANDIT,PYTHON_BLACK,PYTHON_RUFF,REPOSITORY_TRIVY"
@@ -45,23 +45,40 @@ npx mega-linter-runner@beta --custom-flavor-setup --custom-flavor-linters "PYTHO
4545

4646
Select your custom flavor label and the linters you want to include.
4747

48-
![](assets/images/custom-flavor-linter-select.png)
48+
![Selection of linters in the custom flavor](assets/images/custom-flavor-linter-select.png)
4949

5050
### Generated files
5151

5252
The generator will create all necessary configuration files, GitHub Actions workflows, and documentation in your repository.
5353

5454
Two workflows are generated:
55+
5556
- **megalinter-custom-flavor-builder.yml**: Builds and publishes your custom flavor Docker image
5657
- **check-new-megalinter-version.yml**: Automatically checks daily for new MegaLinter releases and creates matching releases in your repository
5758

58-
![](assets/images/custom-flavor-generated-files.png)
59+
![Custom flavor generated files in VS Code](assets/images/custom-flavor-generated-files.png)
60+
61+
### Optional: Generate the image for ARM
62+
63+
> **Important:** Check the [linters you have selected](all_linters.md) in your flavor to see if they are compatible with `linux/arm64` platform.
64+
65+
To build the image for ARM as well, edit **megalinter-custom-flavor-builder.yml** and change:
66+
67+
```yml
68+
platform: "linux/amd64"
69+
```
70+
71+
To:
72+
73+
```yml
74+
platform: "linux/amd64,linux/arm64"
75+
```
5976
6077
### Commit and push your changes
6178
6279
Commit and push the generated files to GitHub.
6380
64-
![](assets/images/custom-flavor-commit-push.png)
81+
![Commit in VS Code](assets/images/custom-flavor-commit-push.png)
6582
6683
### Configure Personal Access Token (Required)
6784
@@ -106,17 +123,15 @@ Your custom flavor will be built and published automatically in two ways:
106123
- Push to any branch (except main) to build a `beta` tagged image
107124
- Manually run the `megalinter-custom-flavor-builder` workflow
108125

109-
![](assets/images/custom-flavor-release-1.png)
126+
![Creating a GitHub release checks](assets/images/custom-flavor-release-1.png)
110127

111-
![](assets/images/custom-flavor-release-2.png)
112-
113-
![](assets/images/custom-flavor-build-job.png)
128+
![Creating a GitHub release form](assets/images/custom-flavor-release-2.png)
114129

115130
## Use a Custom Flavor
116131

117132
Follow [MegaLinter installation guide](https://megalinter.io/latest/install-assisted/), and replace related elements in the workflow.
118133

119-
![](assets/images/custom-flavor-run.png)
134+
![Running a custom flavor workflow](assets/images/custom-flavor-run.png)
120135

121136
### GitHub Action
122137

@@ -175,11 +190,3 @@ Your custom flavor automatically stays up to date with MegaLinter releases:
175190
3. The builder workflow will automatically create your custom flavor using that MegaLinter version
176191

177192
**Troubleshooting**: If automatic version checking isn't working, ensure you have configured the `PAT_TOKEN` secret as described in the setup instructions above.
178-
179-
180-
181-
182-
183-
184-
185-

flavors/custom-builder/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ inputs:
66
megalinter-custom-flavor-builder-tag:
77
description: "Tag of the megalinter-custom-flavor-builder Docker image to use"
88
required: true
9+
platform:
10+
description: "The platform(s) it will build on"
11+
required: true
12+
default: "linux/amd64"
913
is-latest:
1014
description: "Is this the latest version of the custom flavor?"
1115
required: true
@@ -32,6 +36,7 @@ runs:
3236
-v /var/run/docker.sock:/var/run/docker.sock:rw \
3337
-v ${{ github.workspace }}:/github/workspace \
3438
-e GITHUB_TOKEN=${{ env.GITHUB_TOKEN }} \
39+
-e CUSTOM_FLAVOR_PLATFORM=${{ inputs.platform }} \
3540
-e CUSTOM_FLAVOR_BUILD_REPO=${{ env.CUSTOM_FLAVOR_BUILD_REPO }} \
3641
-e CUSTOM_FLAVOR_BUILD_REPO_URL=${{ env.CUSTOM_FLAVOR_BUILD_REPO_URL }} \
3742
-e CUSTOM_FLAVOR_BUILD_USER=${{ env.CUSTOM_FLAVOR_BUILD_USER }} \

mega-linter-runner/generators/mega-linter-custom-flavor/templates/megalinter-custom-flavor-builder.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ jobs:
107107
uses: oxsecurity/megalinter/flavors/custom-builder@main
108108
with:
109109
megalinter-custom-flavor-builder-tag: ${{ steps.determine-tag.outputs.tag }}
110+
platform: "linux/amd64"
110111
is-latest: ${{ steps.determine-tag.outputs.is-latest }}
111112
upload-to-ghcr: "true"
112113
upload-to-dockerhub: ${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_PASSWORD != '' && 'true' || 'false' }}

0 commit comments

Comments
 (0)