Skip to content

Commit

Permalink
chore: Use matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinblackman committed Mar 11, 2024
1 parent 7f5643c commit cd3be60
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 45 deletions.
32 changes: 4 additions & 28 deletions .devcontainer/build.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,12 @@ set -e
PROGDIR=$(dirname "$(readlink -f "$0")")
cd "$PROGDIR/.."

BUILD_ARCH="$1"

(
cd tools/node
npm ci
)

echo "[BUILD] Building arm64"
tools/node/node_modules/.bin/devcontainer build --workspace-folder . --config ./.devcontainer/devcontainer-src.json --push --platform "linux/arm64" --image-name ghcr.io/dustinblackman/devcontainer-oatmeal:latest-arm64
echo "[BUILD] Building amd64"
tools/node/node_modules/.bin/devcontainer build --workspace-folder . --config ./.devcontainer/devcontainer-src.json --push --platform "linux/amd64" --image-name ghcr.io/dustinblackman/devcontainer-oatmeal:latest-amd64
echo "[BUILD] Creating manifest"
docker buildx imagetools create -t ghcr.io/dustinblackman/devcontainer-oatmeal:latest ghcr.io/dustinblackman/devcontainer-oatmeal:latest-arm64 ghcr.io/dustinblackman/devcontainer-oatmeal:latest-amd64
BUILD_SHA=$(docker buildx imagetools inspect ghcr.io/dustinblackman/devcontainer-oatmeal:latest | grep 'Digest' | awk '{print $2}')
echo "[BUILD] Manifest SHA: ${BUILD_SHA}"

echo "[BUILD] Updating docker-compose.yml"
DC_UPDATE=$(yq ".services.oatmeal.image = \"ghcr.io/dustinblackman/devcontainer-oatmeal@${BUILD_SHA}\"" ./.devcontainer/docker-compose.yml)
rm ./.devcontainer/docker-compose.yml
echo "$DC_UPDATE" >./.devcontainer/docker-compose.yml

echo "[BUILD] Creating GitHub PR"
git config --global user.email github-actions[bot]@users.noreply.github.com
git config --global user.name github-actions[bot]
git config pull.rebase false
BUILD_BRANCH="devcontainer-image-update-$GITHUB_RUN_ID"
git checkout -b "$BUILD_BRANCH"
git add ./.devcontainer/docker-compose.yml
git commit -m 'chore: Update dev container image sha'
git push origin "$BUILD_BRANCH"
gh pr create \
--title "[CI] Update devcontainer to $BUILD_SHA" \
--body "Updates the dev container image based on the changes made in https://github.com/dustinblackman/oatmeal/commit/${GITHUB_SHA}"

echo "[BUILD] Done"
echo "[BUILD] Building $BUILD_ARCH"
tools/node/node_modules/.bin/devcontainer build --workspace-folder . --config ./.devcontainer/devcontainer-src.json --push --platform "linux/$BUILD_ARCH" --image-name ghcr.io/dustinblackman/devcontainer-oatmeal:latest-"$BUILD_ARCH"
40 changes: 40 additions & 0 deletions .devcontainer/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -e

PROGDIR=$(dirname "$(readlink -f "$0")")
cd "$PROGDIR/.."

(
cd tools/node
npm ci
)

echo "[BUILD] Pulling arm64"
docker pull ghcr.io/dustinblackman/devcontainer-oatmeal:latest-arm64
echo "[BUILD] Pulling amd64"
docker pull ghcr.io/dustinblackman/devcontainer-oatmeal:latest-amd64
echo "[BUILD] Creating manifest"
docker buildx imagetools create -t ghcr.io/dustinblackman/devcontainer-oatmeal:latest ghcr.io/dustinblackman/devcontainer-oatmeal:latest-arm64 ghcr.io/dustinblackman/devcontainer-oatmeal:latest-amd64
BUILD_SHA=$(docker buildx imagetools inspect ghcr.io/dustinblackman/devcontainer-oatmeal:latest | grep 'Digest' | awk '{print $2}')
echo "[BUILD] Manifest SHA: ${BUILD_SHA}"

echo "[BUILD] Updating docker-compose.yml"
DC_UPDATE=$(yq ".services.oatmeal.image = \"ghcr.io/dustinblackman/devcontainer-oatmeal@${BUILD_SHA}\"" ./.devcontainer/docker-compose.yml)
rm ./.devcontainer/docker-compose.yml
echo "$DC_UPDATE" >./.devcontainer/docker-compose.yml

echo "[BUILD] Creating GitHub PR"
git config --global user.email github-actions[bot]@users.noreply.github.com
git config --global user.name github-actions[bot]
git config pull.rebase false
BUILD_BRANCH="devcontainer-image-update-$GITHUB_RUN_ID"
git checkout -b "$BUILD_BRANCH"
git add ./.devcontainer/docker-compose.yml
git commit -m 'chore: Update dev container image sha'
git push origin "$BUILD_BRANCH"
gh pr create \
--title "[CI] Update devcontainer to $BUILD_SHA" \
--body "Updates the dev container image based on the changes made in https://github.com/dustinblackman/oatmeal/commit/${GITHUB_SHA}"

echo "[BUILD] Done"
39 changes: 36 additions & 3 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,43 @@ on:
- '.devcontainer/devcontainer-src.json'
- '.devcontainer/build.sh'
- '.github/workflows/devcontainer.yml'

name: devcontainer
jobs:
devcontainer:
build:
runs-on: ubuntu-latest
strategy:
matrix:
arch: ["arm64", "amd64"]
permissions:
packages: write
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
# v3
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3
with:
image: tonistiigi/binfmt@sha256:6088cbd69c369178ffd6b68992f342c3a9d5c3cc619bbaa4bfe9a98cb23893d0
- name: Set up Docker Buildx
# v3.1.0
uses: docker/setup-buildx-action@0d103c3126aa41d772a8362f6aa67afac040f80c
- name: Login to GitHub Container Registry
# v3.0.0
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- uses: actions/setup-node@v4
with:
node-version: 18.19.0
- name: Build
run: |
./.devcontainer/build.sh ${{ matrix.arch }}
release:
runs-on: ubuntu-latest
needs: [build]
permissions:
contents: write
pull-requests: write
Expand All @@ -35,7 +68,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 18.19.0
- name: Build
- name: Release
env:
GH_TOKEN: ${{ github.token }}
run: |
Expand All @@ -45,4 +78,4 @@ jobs:
exit 1
fi
sudo chmod +x /usr/local/bin/yq
./.devcontainer/build.sh
./.devcontainer/release.sh
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,22 @@ vergen = { version = "=8.2.5", features = ["build", "git", "gitcl"] }
walkdir = { version = "=2.4.0" }

[package.metadata.bin]
cargo-about = { version = "0.6.0" }
cargo-binstall = { version = "1.4.9", git = "https://github.com/dustinblackman/cargo-binstall", rev = "ce72b764eeeceab8bce907cb3d4ffedff7e1e7e3" }
cargo-cmd = { version = "0.3.1" }
cargo-deny = { version = "0.14.2" }
cargo-gha = { version = "1.0.2" }
cargo-insta = { version = "1.34.0" }
cargo-llvm-cov = { version = "0.5.25" }
cargo-about = { version = "0.6.0", locked = true }
cargo-binstall = { version = "1.4.9", git = "https://github.com/dustinblackman/cargo-binstall", rev = "ce72b764eeeceab8bce907cb3d4ffedff7e1e7e3", locked = true }
cargo-cmd = { version = "0.3.1", locked = true }
cargo-deny = { version = "0.14.2", locked = true }
cargo-gha = { version = "1.0.2", locked = true }
cargo-insta = { version = "1.34.0", locked = true }
cargo-llvm-cov = { version = "0.5.25", locked = true }
cargo-nextest = { version = "0.9.59", locked = true }
cargo-watch = { version = "8.4.0" }
cargo-xwin = { version = "0.16.2" }
cargo-zigbuild = { version = "0.18.1" }
committed = { version = "1.0.20" }
cargo-watch = { version = "8.4.0", locked = true }
cargo-xwin = { version = "0.16.2", locked = true }
cargo-zigbuild = { version = "0.18.1", locked = true }
committed = { version = "1.0.20", locked = true }
flamegraph = { version = "0.5.1", bins = ["cargo-flamegraph"] }
git-cliff = { version = "1.3.1" }
mise = { version = "2024.1.20" }
samply = { version = "0.11.0" }
git-cliff = { version = "1.3.1", locked = true }
mise = { version = "2024.1.20", locked = true }
samply = { version = "0.11.0", locked = true }

[profile.release]
codegen-units = 1
Expand Down

0 comments on commit cd3be60

Please sign in to comment.