Skip to content

Commit 28bcb9e

Browse files
committed
init
0 parents  commit 28bcb9e

File tree

11 files changed

+412
-0
lines changed

11 files changed

+412
-0
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: Build Docker images
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# run every sunday at midnight
7+
- cron: "0 0 * * 0"
8+
push:
9+
branches:
10+
- main
11+
pull_request:
12+
branches:
13+
- main
14+
15+
jobs:
16+
17+
generate-jobs:
18+
name: Generate jobs
19+
runs-on: ubuntu-latest
20+
outputs:
21+
biome-versions: ${{ steps.matrix.outputs.BIOME_VERSIONS }}
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
- name: Setup Bun
26+
uses: oven-sh/setup-bun@v1
27+
- name: Install dependencies
28+
run: bun install
29+
- name: Generate matrix
30+
id: matrix
31+
run: |
32+
BIOME_VERSIONS=$(bun run ./scripts/generate-versions.ts)
33+
echo "BIOME_VERSIONS=$BIOME_VERSIONS" >> $GITHUB_OUTPUT
34+
35+
build-images-arm64:
36+
name: ${{ matrix.versions.patch }} (arm64)
37+
needs: generate-jobs
38+
concurrency: build-images-${{ matrix.versions.patch }}-arm64
39+
permissions:
40+
packages: write
41+
runs-on: ubuntu-22.04-arm
42+
strategy:
43+
matrix:
44+
versions: ${{ fromJson(needs.generate-jobs.outputs.biome-versions) }}
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v4
48+
- name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@v3
50+
- name: Log in to the Container registry
51+
uses: docker/login-action@v3
52+
with:
53+
registry: ghcr.io
54+
username: ${{ github.actor }}
55+
password: ${{ secrets.GITHUB_TOKEN }}
56+
- name: Build and push
57+
uses: docker/build-push-action@v6
58+
with:
59+
push: ${{ github.event_name != 'pull_request' }}
60+
provenance: false
61+
platforms: linux/arm64
62+
tags: ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-arm64
63+
file: Dockerfile
64+
cache-from: type=gha,scope=${{ matrix.versions.patch}}-arm64
65+
cache-to: type=gha,mode=max,scope=${{ matrix.versions.patch}}-arm64
66+
build-args: |
67+
BIOME_VERSION=${{ matrix.versions.patch }}
68+
69+
build-images-amd64:
70+
name: ${{ matrix.versions.patch }} (amd64)
71+
needs: generate-jobs
72+
concurrency: build-images-${{ matrix.versions.patch }}-amd64
73+
permissions:
74+
packages: write
75+
runs-on: ubuntu-22.04
76+
strategy:
77+
matrix:
78+
versions: ${{ fromJson(needs.generate-jobs.outputs.biome-versions) }}
79+
steps:
80+
- name: Checkout
81+
uses: actions/checkout@v4
82+
- name: Set up Docker Buildx
83+
uses: docker/setup-buildx-action@v3
84+
- name: Log in to the Container registry
85+
uses: docker/login-action@v3
86+
with:
87+
registry: ghcr.io
88+
username: ${{ github.actor }}
89+
password: ${{ secrets.GITHUB_TOKEN }}
90+
- name: Build and push
91+
uses: docker/build-push-action@v6
92+
with:
93+
push: ${{ github.event_name != 'pull_request' }}
94+
provenance: false
95+
platforms: linux/amd64
96+
tags: ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-amd64
97+
file: Dockerfile
98+
cache-from: type=gha,scope=${{ matrix.versions.patch}}-amd64
99+
cache-to: type=gha,mode=max,scope=${{ matrix.versions.patch}}-amd64
100+
build-args: |
101+
BIOME_VERSION=${{ matrix.versions.patch }}
102+
103+
stitch-images:
104+
name: Stitch images (${{ matrix.versions.patch }})
105+
needs: [generate-jobs, build-images-arm64, build-images-amd64]
106+
runs-on: ubuntu-latest
107+
permissions:
108+
packages: write
109+
if: ${{ github.event_name != 'pull_request' }}
110+
strategy:
111+
matrix:
112+
versions: ${{ fromJson(needs.generate-jobs.outputs.biome-versions) }}
113+
steps:
114+
- name: Checkout
115+
uses: actions/checkout@v4
116+
- name: Set up Docker Buildx
117+
uses: docker/setup-buildx-action@v3
118+
- name: Log in to the Container registry
119+
uses: docker/login-action@v3
120+
with:
121+
registry: ghcr.io
122+
username: ${{ github.actor }}
123+
password: ${{ secrets.GITHUB_TOKEN }}
124+
125+
- name: Create major version (${{ matrix.versions.major }}) manifest
126+
if: ${{ matrix.versions.createMajor }}
127+
run: |
128+
docker manifest create ghcr.io/biomejs/biome:${{ matrix.versions.major }} \
129+
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-arm64 \
130+
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-amd64
131+
docker manifest push ghcr.io/biomejs/biome:${{ matrix.versions.major }}
132+
133+
- name: Create minor version (${{ matrix.versions.minor }}) manifest
134+
if: ${{ matrix.versions.createMinor }}
135+
run: |
136+
docker manifest create ghcr.io/biomejs/biome:${{ matrix.versions.minor }} \
137+
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-arm64 \
138+
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-amd64
139+
docker manifest push ghcr.io/biomejs/biome:${{ matrix.versions.minor }}
140+
141+
- name: Create patch version (${{ matrix.versions.patch }}) manifest
142+
run: |
143+
docker manifest create ghcr.io/biomejs/biome:${{ matrix.versions.patch }} \
144+
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-arm64 \
145+
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-amd64
146+
docker manifest push ghcr.io/biomejs/biome:${{ matrix.versions.patch }}
147+
148+
- name: Create latest (${{ matrix.versions.patch }}) manifest
149+
if: ${{ matrix.versions.patch == fromJson(needs.generate-jobs.outputs.biome-versions)[0].patch }}
150+
run: |
151+
docker manifest create ghcr.io/biomejs/biome:latest \
152+
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-arm64 \
153+
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-amd64
154+
docker manifest push ghcr.io/biomejs/biome:latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
ARG ALPINE_VERSION=3.20
2+
3+
FROM rust:1.81.0-alpine${ALPINE_VERSION} AS builder
4+
5+
ARG BIOME_VERSION=1.9.2
6+
ENV BIOME_VERSION=${BIOME_VERSION}
7+
8+
WORKDIR /usr/src/biome
9+
10+
# Install build dependencies
11+
RUN apk add --no-cache musl-dev make
12+
13+
# Downloads the tarball for the version of Biome we want to build from GitHub Releases
14+
ADD https://github.com/biomejs/biome/archive/refs/tags/cli/v${BIOME_VERSION}.tar.gz /tmp/biome.tar.gz
15+
16+
# Extract the tarball into the working directory
17+
RUN tar -xzvf /tmp/biome.tar.gz -C /usr/src/biome/ --strip-components=1
18+
19+
# Build the biome binary
20+
ENV RUSTFLAGS="-C strip=symbols"
21+
RUN cargo build -p biome_cli --release
22+
23+
FROM scratch AS biome
24+
25+
COPY --from=builder /usr/src/biome/target/release/biome /usr/local/bin/biome
26+
27+
WORKDIR /code
28+
29+
ENTRYPOINT [ "/usr/local/bin/biome" ]

LICENSE.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
The MIT License (MIT)
2+
=====================
3+
4+
Copyright © `2024` `Nicolas Hedger <[email protected]>`
5+
6+
Permission is hereby granted, free of charge, to any person
7+
obtaining a copy of this software and associated documentation
8+
files (the “Software”), to deal in the Software without
9+
restriction, including without limitation the rights to use,
10+
copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following
13+
conditions:
14+
15+
The above copyright notice and this permission notice shall be
16+
included in all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
19+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25+
OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Docker images for Biome
2+
3+
This repository contain the source code for building the official Docker images
4+
for Biome.
5+
6+
Supported architectures: `amd64`, `arm64`
7+
8+
## Supported tags
9+
10+
Docker images are available for all versions of Biome starting from `1.7.0`.
11+
12+
Images are tagged with the following format:
13+
14+
```sh
15+
ghcr.io/biomejs/biome:{major}
16+
ghcr.io/biomejs/biome:{major}{minor}
17+
ghcr.io/biomejs/biome:{major}{minor}{patch}
18+
```
19+
20+
### Examples
21+
- `ghcr.io/biomejs/biome:1`
22+
- `ghcr.io/biomejs/biome:1.9`
23+
- `ghcr.io/biomejs/biome:1.9.4`
24+
- `ghcr.io/biomejs/biome:latest`
25+
26+
## Usage
27+
28+
The default working directory is set to `/code` in the container.
29+
30+
```sh
31+
# Check files
32+
docker run -v $(pwd):/code ghcr.io/biomejs/biome:1.9.4 biome check
33+
docker run -v $(pwd):/code ghcr.io/biomejs/biome:1.9.4 biome check --write
34+
35+
# Lint files
36+
docker run -v $(pwd):/code ghcr.io/biomejs/biome:1.9.4 biome lint
37+
docker run -v $(pwd):/code ghcr.io/biomejs/biome:1.9.4 biome lint --write
38+
39+
# Format files
40+
docker run -v $(pwd):/code ghcr.io/biomejs/biome:1.9.4 biome format
41+
docker run -v $(pwd):/code ghcr.io/biomejs/biome:1.9.4 biome format --write
42+
```
43+
44+
## License
45+
46+
This project is licensed under the [MIT License](LICENSE.md).

biome.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"clientKind": "git",
6+
"useIgnoreFile": false
7+
}
8+
}

bun.lockb

8.24 KB
Binary file not shown.

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "biome-docker",
3+
"type": "module",
4+
"devDependencies": {
5+
"@types/bun": "latest",
6+
"@types/semver": "^7.5.8"
7+
},
8+
"peerDependencies": {
9+
"typescript": "^5.0.0"
10+
},
11+
"dependencies": {
12+
"@biomejs/biome": "^1.9.4",
13+
"@biomejs/version-utils": "^0.4.0",
14+
"semver": "^7.6.3"
15+
}
16+
}

scripts/generate-versions.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { getAllVersions } from "@biomejs/version-utils";
2+
import { type SemVer, coerce, gt, gte } from "semver";
3+
4+
const yankedVersions: string[] = [];
5+
6+
const semverVersions = ((await getAllVersions(false)) ?? [])
7+
?.map((v) => coerce(v))
8+
.filter((v) => v !== null)
9+
.filter((v) => gte(v, "1.7.0"))
10+
.filter((v) => !yankedVersions.includes(v.format()));
11+
12+
const getGreatestMinorForMajor = (versions: SemVer[]): Map<string, string> => {
13+
const greatestMinorVersionForMajor: Map<string, string> = new Map<
14+
string,
15+
string
16+
>([]);
17+
18+
for (const version of versions ?? []) {
19+
const semver = version;
20+
21+
if (!semver?.major) {
22+
continue;
23+
}
24+
25+
if (!greatestMinorVersionForMajor.has(`${semver.major}`)) {
26+
greatestMinorVersionForMajor.set(`${semver.major}`, version.format());
27+
} else {
28+
const newMax = coerce(
29+
greatestMinorVersionForMajor.get(`${semver.major}`),
30+
);
31+
32+
if (!newMax) {
33+
continue;
34+
}
35+
36+
if (gt(semver, newMax)) {
37+
greatestMinorVersionForMajor.set(`${semver.major}`, version.format());
38+
}
39+
}
40+
}
41+
42+
return greatestMinorVersionForMajor;
43+
};
44+
45+
const getGreatestPatchForMajorMinor = (
46+
versions: SemVer[],
47+
): Map<string, string> => {
48+
const greatestPatchVersionForMajor: Map<string, string> = new Map<
49+
string,
50+
string
51+
>([]);
52+
53+
for (const version of versions ?? []) {
54+
const semver = version;
55+
56+
if (!semver?.major || !semver?.minor) {
57+
continue;
58+
}
59+
60+
if (!greatestPatchVersionForMajor.has(`${semver.major}.${semver.minor}`)) {
61+
greatestPatchVersionForMajor.set(
62+
`${semver.major}.${semver.minor}`,
63+
version.format(),
64+
);
65+
} else {
66+
const newMax = coerce(
67+
greatestPatchVersionForMajor.get(`${semver.major}.${semver.minor}`),
68+
);
69+
70+
if (!newMax) {
71+
continue;
72+
}
73+
74+
if (gt(semver, newMax)) {
75+
greatestPatchVersionForMajor.set(
76+
`${semver.major}.${semver.minor}`,
77+
version.format(),
78+
);
79+
}
80+
}
81+
}
82+
83+
return greatestPatchVersionForMajor;
84+
};
85+
86+
const greatestMinorForMajor = getGreatestMinorForMajor(semverVersions);
87+
const greatestPatchForMajorMinor =
88+
getGreatestPatchForMajorMinor(semverVersions);
89+
90+
/**
91+
* Generate a list of all verions of Biome for which we want to create
92+
* Docker images.
93+
*/
94+
export const versions = semverVersions.map((version: SemVer) => ({
95+
major: `${version.major}`,
96+
minor: `${version.major}.${version.minor}`,
97+
patch: version.format(),
98+
createMajor:
99+
greatestMinorForMajor.get(`${version.major}`) === version.format(),
100+
createMinor:
101+
greatestPatchForMajorMinor.get(`${version.major}.${version.minor}`) ===
102+
version.format(),
103+
}));
104+
105+
console.log(JSON.stringify(versions));

0 commit comments

Comments
 (0)