ci: build docker images with nix
Signed-off-by: seth <getchoo@tuta.io>
This commit is contained in:
parent
a26a2fd484
commit
4b80ec7345
3 changed files with 53 additions and 94 deletions
|
@ -1,6 +0,0 @@
|
||||||
node_modules/
|
|
||||||
.git/
|
|
||||||
|
|
||||||
.env
|
|
||||||
.env.*
|
|
||||||
!.env.example
|
|
130
.github/workflows/docker.yml
vendored
130
.github/workflows/docker.yml
vendored
|
@ -3,112 +3,88 @@ name: Docker
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ['main']
|
branches: ['main']
|
||||||
|
pull_request:
|
||||||
env:
|
workflow_dispatch:
|
||||||
REGISTRY: ghcr.io
|
|
||||||
IMAGE_NAME: prismlauncher/refraction
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
packages: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
name: Build image
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
platform:
|
arch: [x86_64, aarch64]
|
||||||
- linux/arm64
|
|
||||||
- linux/amd64
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
|
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Install Nix
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: DeterminateSystems/nix-installer-action@v8
|
||||||
if: ${{ matrix.platform != 'linux/amd64' }}
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Setup Nix cache
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: DeterminateSystems/magic-nix-cache-action@v2
|
||||||
|
|
||||||
- name: Log in to the Container registry
|
- name: Build Docker image
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Extract metadata (tags, labels) for Docker
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
||||||
tags: |
|
|
||||||
type=ref,event=branch
|
|
||||||
type=raw,value=latest
|
|
||||||
|
|
||||||
- name: Build and push by digest
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
id: build
|
id: build
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
provenance: false
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
platforms: ${{ matrix.platform }}
|
|
||||||
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
|
|
||||||
|
|
||||||
- name: Export digests
|
|
||||||
run: |
|
run: |
|
||||||
mkdir -p /tmp/digests
|
nix build -L --accept-flake-config .#container-${{ matrix.arch }}
|
||||||
digest="${{ steps.build.outputs.digest }}"
|
[ ! -L result ] && exit 1
|
||||||
touch "/tmp/digests/${digest#sha256:}"
|
echo "path=$(realpath result)" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Upload digests
|
- name: Upload image
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: digests
|
name: container-${{ matrix.arch }}
|
||||||
path: /tmp/digests/*
|
path: ${{ steps.build.outputs.path }}
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
push:
|
push:
|
||||||
|
name: Push image
|
||||||
|
|
||||||
|
needs: build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs:
|
|
||||||
- build
|
permissions:
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
USERNAME: ${{ github.actor }}
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
|
if: github.event_name == 'push'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Download digests
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Download images
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: digests
|
path: images
|
||||||
path: /tmp/digests
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Login to registry
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Log in to the Container registry
|
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
username: ${{ github.actor }}
|
username: ${{ env.USERNAME }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ github.token }}
|
||||||
|
|
||||||
- name: Extract metadata (tags, labels) for Docker
|
- name: Push to registry
|
||||||
id: meta
|
env:
|
||||||
uses: docker/metadata-action@v5
|
TAG: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||||
with:
|
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
||||||
tags: |
|
|
||||||
type=ref,event=branch
|
|
||||||
type=raw,value=latest
|
|
||||||
|
|
||||||
- name: Create manifest list and push
|
|
||||||
working-directory: /tmp/digests
|
|
||||||
run: |
|
run: |
|
||||||
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
|
set -eux
|
||||||
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
|
|
||||||
|
|
||||||
- name: Inspect image
|
architectures=("x86_64" "aarch64")
|
||||||
run: |
|
for arch in "${architectures[@]}"; do
|
||||||
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
|
docker load < images/container-"$arch"/*.tar.gz
|
||||||
|
docker tag refraction:latest-"$arch" ${{ env.TAG }}-"$arch"
|
||||||
|
docker push ${{ env.TAG }}-"$arch"
|
||||||
|
done
|
||||||
|
|
||||||
|
docker manifest create ${{ env.TAG }} \
|
||||||
|
--amend ${{ env.TAG }}-x86_64 \
|
||||||
|
--amend ${{ env.TAG }}-aarch64
|
||||||
|
|
||||||
|
docker manifest push ${{ env.TAG }}
|
||||||
|
|
11
Dockerfile
11
Dockerfile
|
@ -1,11 +0,0 @@
|
||||||
FROM docker.io/library/node:21-alpine
|
|
||||||
RUN corepack enable
|
|
||||||
RUN corepack prepare pnpm@latest --activate
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY package.json pnpm-lock.yaml .
|
|
||||||
RUN pnpm install --frozen-lockfile
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
CMD [ "pnpm", "run", "start" ]
|
|
Loading…
Add table
Add a link
Reference in a new issue