160 lines
5.0 KiB
YAML
160 lines
5.0 KiB
YAML
name: Docker Image CI
|
|
on:
|
|
push:
|
|
tags:
|
|
- "*"
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
frontend-build:
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v6.0.2
|
|
with:
|
|
submodules: recursive
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: 24
|
|
- name: Install dependencies and build frontend
|
|
run: |
|
|
cd frontend
|
|
npm install
|
|
npm run build
|
|
- name: Upload frontend build artifact
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: frontend-dist
|
|
path: frontend/dist/
|
|
|
|
build:
|
|
needs: frontend-build
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- { platform: linux/amd64 }
|
|
- { platform: linux/386 }
|
|
- { platform: linux/arm64/v8 }
|
|
- { platform: linux/arm/v7 }
|
|
- { platform: linux/arm/v6 }
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v6.0.2
|
|
- name: Download frontend build artifact
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: frontend-dist
|
|
path: frontend_dist
|
|
- name: Prepare
|
|
run: |
|
|
platform="${{ matrix.platform }}"
|
|
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
|
|
- name: Docker meta
|
|
id: meta
|
|
uses: docker/metadata-action@v6
|
|
with:
|
|
images: |
|
|
alireza7/s-ui
|
|
ghcr.io/alireza0/s-ui
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=tag
|
|
type=pep440,pattern={{version}}
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v4
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v4
|
|
- name: Cache Docker layers
|
|
uses: actions/cache@v5
|
|
with:
|
|
path: /tmp/.buildx-cache
|
|
key: ${{ runner.os }}-buildx-${{ matrix.platform }}-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ runner.os }}-buildx-${{ matrix.platform }}-
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v4
|
|
with:
|
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
|
- name: Login to GHCR
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Build and push by digest
|
|
id: build
|
|
uses: docker/build-push-action@v7
|
|
with:
|
|
context: .
|
|
file: Dockerfile.frontend-artifact
|
|
platforms: ${{ matrix.platform }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
tags: |
|
|
alireza7/s-ui
|
|
ghcr.io/alireza0/s-ui
|
|
cache-from: type=local,src=/tmp/.buildx-cache
|
|
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
|
|
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
|
|
- name: Export digest
|
|
run: |
|
|
mkdir -p ${{ runner.temp }}/digests
|
|
digest="${{ steps.build.outputs.digest }}"
|
|
echo "${digest#sha256:}" > "${{ runner.temp }}/digests/${digest#sha256:}"
|
|
- name: Upload digest
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: digests-${{ env.PLATFORM_PAIR }}
|
|
path: ${{ runner.temp }}/digests/*
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
merge:
|
|
needs: build
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- name: Download digests
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
path: ${{ runner.temp }}/digests
|
|
pattern: digests-*
|
|
merge-multiple: true
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v4
|
|
with:
|
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
|
- name: Login to GHCR
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v4
|
|
- name: Docker meta
|
|
id: meta
|
|
uses: docker/metadata-action@v6
|
|
with:
|
|
images: |
|
|
alireza7/s-ui
|
|
ghcr.io/alireza0/s-ui
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=tag
|
|
type=pep440,pattern={{version}}
|
|
- name: Create manifest list and push
|
|
env:
|
|
DOCKER_METADATA_OUTPUT_JSON: ${{ steps.meta.outputs.json }}
|
|
working-directory: ${{ runner.temp }}/digests
|
|
run: |
|
|
set -e
|
|
for img in alireza7/s-ui ghcr.io/alireza0/s-ui; do
|
|
TAGS_ARGS=$(echo "$DOCKER_METADATA_OUTPUT_JSON" | jq -cr --arg img "$img" '.tags | map(select(startswith($img))) | map("-t " + .) | join(" ")')
|
|
DIGEST_REFS=$(for f in *; do echo -n "${img}@sha256:$(cat "$f") "; done)
|
|
docker buildx imagetools create $TAGS_ARGS $DIGEST_REFS
|
|
done
|