Skip to content

Commit

Permalink
test self hosted runner
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenrayhorn committed Oct 28, 2024
1 parent 3650d39 commit d202e44
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 138 deletions.
131 changes: 2 additions & 129 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- test

jobs:
build-amd64:
Expand All @@ -18,11 +19,6 @@ jobs:
with:
ref: "${{ inputs.ref }}"

- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3
with:
platforms: 'amd64'

- name: Login to registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
Expand All @@ -33,52 +29,6 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3

- name: Make cache IDs
id: run_number
run: |
RUN_NUMBER=${{ github.run_number }}
PREV_RN=$(( RUN_NUMBER - 1 ))
NEXT_RN=$(( RUN_NUMBER ))
echo "next_rn=$NEXT_RN" >> $GITHUB_OUTPUT
echo "prev_rn=$PREV_RN" >> $GITHUB_OUTPUT
- name: Restore cache
uses: actions/cache/restore@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4
id: cache-restore
with:
path: |
sccache
key: rust-sccache-amd64-${{ steps.run_number.outputs.prev_rn }}

- name: Delete old cache
run: |
gh extension install actions/gh-actions-cache
set +e
gh actions-cache delete "rust-sccache-amd64-${{ steps.run_number.outputs.prev_rn }}" -R $REPO -B main --confirm
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}

- name: Setup cache save
uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4
id: cache-restore-save
with:
path: |
sccache
key: rust-sccache-amd64-${{ steps.run_number.outputs.next_rn }}
save-always: true

- name: Inject cache into docker
uses: reproducible-containers/buildkit-cache-dance@5b6db76d1da5c8b307d5d2e0706d266521b710de # v3.1.2
with:
cache-map: |
{
"sccache": "/sccache-cache"
}
- name: Build and push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
Expand All @@ -92,7 +42,7 @@ jobs:

build-arm64:
name: arm64 image
runs-on: ubuntu-latest
runs-on: [self-hosted, arm64]
permissions:
packages: write
actions: write
Expand All @@ -102,11 +52,6 @@ jobs:
with:
ref: "${{ inputs.ref }}"

- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3
with:
platforms: 'arm64'

- name: Login to registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
Expand All @@ -117,52 +62,6 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3

- name: Make cache IDs
id: run_number
run: |
RUN_NUMBER=${{ github.run_number }}
PREV_RN=$(( RUN_NUMBER - 1 ))
NEXT_RN=$(( RUN_NUMBER ))
echo "next_rn=$NEXT_RN" >> $GITHUB_OUTPUT
echo "prev_rn=$PREV_RN" >> $GITHUB_OUTPUT
- name: Restore cache
uses: actions/cache/restore@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4
id: cache-restore
with:
path: |
sccache
key: rust-sccache-arm64-${{ steps.run_number.outputs.prev_rn }}

- name: Delete old cache
run: |
gh extension install actions/gh-actions-cache
set +e
gh actions-cache delete "rust-sccache-arm64-${{ steps.run_number.outputs.prev_rn }}" -R $REPO -B main --confirm
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}

- name: Setup cache save
uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4
id: cache-restore-save
with:
path: |
sccache
key: rust-sccache-arm64-${{ steps.run_number.outputs.next_rn }}
save-always: true

- name: Inject cache into docker
uses: reproducible-containers/buildkit-cache-dance@5b6db76d1da5c8b307d5d2e0706d266521b710de # v3.1.2
with:
cache-map: |
{
"sccache": "/sccache-cache"
}
- name: Build and push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
Expand All @@ -174,29 +73,3 @@ jobs:
cache-from: type=registry,ref=ghcr.io/bradenrayhorn/mise:buildcache-arm64
cache-to: type=registry,ref=ghcr.io/bradenrayhorn/mise:buildcache-arm64,mode=max

retag-next:
name: Push multiarch image
runs-on: ubuntu-latest
permissions:
packages: write
needs: [build-arm64, build-amd64]
steps:
- name: Login to registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3

- name: Retag
run: |
IMAGE=ghcr.io/bradenrayhorn/mise
docker buildx imagetools create \
--tag $IMAGE:next \
--tag $IMAGE:next-${{ github.sha }} \
$IMAGE:building-block-amd64-${{ github.sha }} \
$IMAGE:building-block-arm64-${{ github.sha }}
10 changes: 1 addition & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,11 @@ RUN npm run build
# build server
FROM rust_base as server_builder

Check warning on line 32 in Dockerfile

View workflow job for this annotation

GitHub Actions / amd64 image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 32 in Dockerfile

View workflow job for this annotation

GitHub Actions / arm64 image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

RUN wget -O sccache.tar.gz https://github.com/mozilla/sccache/releases/download/v0.8.1/sccache-v0.8.1-$(uname -m)-unknown-linux-musl.tar.gz \
&& tar xzf sccache.tar.gz \
&& mv sccache-v0.8.1-$(uname -m)-unknown-linux-musl/sccache /usr/local/bin/sccache \
&& chmod +x /usr/local/bin/sccache;

ENV SCCACHE_DIR=/sccache-cache
ENV RUSTC_WRAPPER="/usr/local/bin/sccache"

RUN mkdir /app
COPY /server app/
WORKDIR /app

RUN --mount=type=cache,target=/sccache-cache cargo build --release && sccache --show-stats
RUN ls -lah && cargo build --release

# assemble final image
FROM alpine:3.20@sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d
Expand Down

0 comments on commit d202e44

Please sign in to comment.