Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
nhedger committed Jan 18, 2025
0 parents commit 28bcb9e
Show file tree
Hide file tree
Showing 11 changed files with 412 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*
154 changes: 154 additions & 0 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
name: Build Docker images

on:
workflow_dispatch:
schedule:
# run every sunday at midnight
- cron: "0 0 * * 0"
push:
branches:
- main
pull_request:
branches:
- main

jobs:

generate-jobs:
name: Generate jobs
runs-on: ubuntu-latest
outputs:
biome-versions: ${{ steps.matrix.outputs.BIOME_VERSIONS }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install
- name: Generate matrix
id: matrix
run: |
BIOME_VERSIONS=$(bun run ./scripts/generate-versions.ts)
echo "BIOME_VERSIONS=$BIOME_VERSIONS" >> $GITHUB_OUTPUT
build-images-arm64:
name: ${{ matrix.versions.patch }} (arm64)
needs: generate-jobs
concurrency: build-images-${{ matrix.versions.patch }}-arm64
permissions:
packages: write
runs-on: ubuntu-22.04-arm
strategy:
matrix:
versions: ${{ fromJson(needs.generate-jobs.outputs.biome-versions) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: ${{ github.event_name != 'pull_request' }}
provenance: false
platforms: linux/arm64
tags: ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-arm64
file: Dockerfile
cache-from: type=gha,scope=${{ matrix.versions.patch}}-arm64
cache-to: type=gha,mode=max,scope=${{ matrix.versions.patch}}-arm64
build-args: |
BIOME_VERSION=${{ matrix.versions.patch }}
build-images-amd64:
name: ${{ matrix.versions.patch }} (amd64)
needs: generate-jobs
concurrency: build-images-${{ matrix.versions.patch }}-amd64
permissions:
packages: write
runs-on: ubuntu-22.04
strategy:
matrix:
versions: ${{ fromJson(needs.generate-jobs.outputs.biome-versions) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: ${{ github.event_name != 'pull_request' }}
provenance: false
platforms: linux/amd64
tags: ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-amd64
file: Dockerfile
cache-from: type=gha,scope=${{ matrix.versions.patch}}-amd64
cache-to: type=gha,mode=max,scope=${{ matrix.versions.patch}}-amd64
build-args: |
BIOME_VERSION=${{ matrix.versions.patch }}
stitch-images:
name: Stitch images (${{ matrix.versions.patch }})
needs: [generate-jobs, build-images-arm64, build-images-amd64]
runs-on: ubuntu-latest
permissions:
packages: write
if: ${{ github.event_name != 'pull_request' }}
strategy:
matrix:
versions: ${{ fromJson(needs.generate-jobs.outputs.biome-versions) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create major version (${{ matrix.versions.major }}) manifest
if: ${{ matrix.versions.createMajor }}
run: |
docker manifest create ghcr.io/biomejs/biome:${{ matrix.versions.major }} \
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-arm64 \
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-amd64
docker manifest push ghcr.io/biomejs/biome:${{ matrix.versions.major }}
- name: Create minor version (${{ matrix.versions.minor }}) manifest
if: ${{ matrix.versions.createMinor }}
run: |
docker manifest create ghcr.io/biomejs/biome:${{ matrix.versions.minor }} \
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-arm64 \
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-amd64
docker manifest push ghcr.io/biomejs/biome:${{ matrix.versions.minor }}
- name: Create patch version (${{ matrix.versions.patch }}) manifest
run: |
docker manifest create ghcr.io/biomejs/biome:${{ matrix.versions.patch }} \
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-arm64 \
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-amd64
docker manifest push ghcr.io/biomejs/biome:${{ matrix.versions.patch }}
- name: Create latest (${{ matrix.versions.patch }}) manifest
if: ${{ matrix.versions.patch == fromJson(needs.generate-jobs.outputs.biome-versions)[0].patch }}
run: |
docker manifest create ghcr.io/biomejs/biome:latest \
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-arm64 \
ghcr.io/biomejs/biome:${{ matrix.versions.patch }}-amd64
docker manifest push ghcr.io/biomejs/biome:latest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ARG ALPINE_VERSION=3.20

FROM rust:1.81.0-alpine${ALPINE_VERSION} AS builder

ARG BIOME_VERSION=1.9.2
ENV BIOME_VERSION=${BIOME_VERSION}

WORKDIR /usr/src/biome

# Install build dependencies
RUN apk add --no-cache musl-dev make

# Downloads the tarball for the version of Biome we want to build from GitHub Releases
ADD https://github.com/biomejs/biome/archive/refs/tags/cli/v${BIOME_VERSION}.tar.gz /tmp/biome.tar.gz

# Extract the tarball into the working directory
RUN tar -xzvf /tmp/biome.tar.gz -C /usr/src/biome/ --strip-components=1

# Build the biome binary
ENV RUSTFLAGS="-C strip=symbols"
RUN cargo build -p biome_cli --release

FROM scratch AS biome

COPY --from=builder /usr/src/biome/target/release/biome /usr/local/bin/biome

WORKDIR /code

ENTRYPOINT [ "/usr/local/bin/biome" ]
25 changes: 25 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The MIT License (MIT)
=====================

Copyright © `2024` `Nicolas Hedger <[email protected]>`

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Docker images for Biome

This repository contain the source code for building the official Docker images
for Biome.

Supported architectures: `amd64`, `arm64`

## Supported tags

Docker images are available for all versions of Biome starting from `1.7.0`.

Images are tagged with the following format:

```sh
ghcr.io/biomejs/biome:{major}
ghcr.io/biomejs/biome:{major}{minor}
ghcr.io/biomejs/biome:{major}{minor}{patch}
```

### Examples
- `ghcr.io/biomejs/biome:1`
- `ghcr.io/biomejs/biome:1.9`
- `ghcr.io/biomejs/biome:1.9.4`
- `ghcr.io/biomejs/biome:latest`

## Usage

The default working directory is set to `/code` in the container.

```sh
# Check files
docker run -v $(pwd):/code ghcr.io/biomejs/biome:1.9.4 biome check
docker run -v $(pwd):/code ghcr.io/biomejs/biome:1.9.4 biome check --write

# Lint files
docker run -v $(pwd):/code ghcr.io/biomejs/biome:1.9.4 biome lint
docker run -v $(pwd):/code ghcr.io/biomejs/biome:1.9.4 biome lint --write

# Format files
docker run -v $(pwd):/code ghcr.io/biomejs/biome:1.9.4 biome format
docker run -v $(pwd):/code ghcr.io/biomejs/biome:1.9.4 biome format --write
```

## License

This project is licensed under the [MIT License](LICENSE.md).
8 changes: 8 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": false
}
}
Binary file added bun.lockb
Binary file not shown.
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "biome-docker",
"type": "module",
"devDependencies": {
"@types/bun": "latest",
"@types/semver": "^7.5.8"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@biomejs/biome": "^1.9.4",
"@biomejs/version-utils": "^0.4.0",
"semver": "^7.6.3"
}
}
105 changes: 105 additions & 0 deletions scripts/generate-versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { getAllVersions } from "@biomejs/version-utils";
import { type SemVer, coerce, gt, gte } from "semver";

const yankedVersions: string[] = [];

const semverVersions = ((await getAllVersions(false)) ?? [])
?.map((v) => coerce(v))
.filter((v) => v !== null)
.filter((v) => gte(v, "1.7.0"))
.filter((v) => !yankedVersions.includes(v.format()));

const getGreatestMinorForMajor = (versions: SemVer[]): Map<string, string> => {
const greatestMinorVersionForMajor: Map<string, string> = new Map<
string,
string
>([]);

for (const version of versions ?? []) {
const semver = version;

if (!semver?.major) {
continue;
}

if (!greatestMinorVersionForMajor.has(`${semver.major}`)) {
greatestMinorVersionForMajor.set(`${semver.major}`, version.format());
} else {
const newMax = coerce(
greatestMinorVersionForMajor.get(`${semver.major}`),
);

if (!newMax) {
continue;
}

if (gt(semver, newMax)) {
greatestMinorVersionForMajor.set(`${semver.major}`, version.format());
}
}
}

return greatestMinorVersionForMajor;
};

const getGreatestPatchForMajorMinor = (
versions: SemVer[],
): Map<string, string> => {
const greatestPatchVersionForMajor: Map<string, string> = new Map<
string,
string
>([]);

for (const version of versions ?? []) {
const semver = version;

if (!semver?.major || !semver?.minor) {
continue;
}

if (!greatestPatchVersionForMajor.has(`${semver.major}.${semver.minor}`)) {
greatestPatchVersionForMajor.set(
`${semver.major}.${semver.minor}`,
version.format(),
);
} else {
const newMax = coerce(
greatestPatchVersionForMajor.get(`${semver.major}.${semver.minor}`),
);

if (!newMax) {
continue;
}

if (gt(semver, newMax)) {
greatestPatchVersionForMajor.set(
`${semver.major}.${semver.minor}`,
version.format(),
);
}
}
}

return greatestPatchVersionForMajor;
};

const greatestMinorForMajor = getGreatestMinorForMajor(semverVersions);
const greatestPatchForMajorMinor =
getGreatestPatchForMajorMinor(semverVersions);

/**
* Generate a list of all verions of Biome for which we want to create
* Docker images.
*/
export const versions = semverVersions.map((version: SemVer) => ({
major: `${version.major}`,
minor: `${version.major}.${version.minor}`,
patch: version.format(),
createMajor:
greatestMinorForMajor.get(`${version.major}`) === version.format(),
createMinor:
greatestPatchForMajorMinor.get(`${version.major}.${version.minor}`) ===
version.format(),
}));

console.log(JSON.stringify(versions));
Loading

0 comments on commit 28bcb9e

Please sign in to comment.