mirror of
https://github.com/bolucat/Archive.git
synced 2025-12-24 13:28:37 +08:00
Update On Thu Mar 28 19:29:32 CET 2024
This commit is contained in:
92
echo/.github/workflows/cd.yaml
vendored
92
echo/.github/workflows/cd.yaml
vendored
@@ -16,35 +16,14 @@ env:
|
||||
REGISTRY_IMAGE: ehco1996/ehco
|
||||
|
||||
jobs:
|
||||
test:
|
||||
prepare-matrix:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
||||
steps:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.21"
|
||||
id: go
|
||||
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.cache/go-build
|
||||
~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: tidy
|
||||
run: make tidy
|
||||
|
||||
- name: lint
|
||||
run: make lint
|
||||
|
||||
- name: test
|
||||
run: make test
|
||||
- id: set-matrix
|
||||
run: |
|
||||
echo '::set-output name=matrix::{"platform":["amd64","arm64"]}'
|
||||
|
||||
build-bin:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -55,17 +34,18 @@ jobs:
|
||||
go-version: "1.21"
|
||||
id: go
|
||||
|
||||
- uses: actions/cache@v3
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# cache golang build
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cache/go-build
|
||||
~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v4
|
||||
${{ runner.os }}-go-${{ hashFiles('go.sum') }}
|
||||
|
||||
- name: build
|
||||
run: |
|
||||
@@ -77,7 +57,7 @@ jobs:
|
||||
cp ./build/Dockerfile /tmp/ehco/Dockerfile
|
||||
|
||||
- name: Upload binaries
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: binaries
|
||||
path: /tmp/ehco
|
||||
@@ -87,15 +67,14 @@ jobs:
|
||||
build-image:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- prepare-matrix
|
||||
- build-bin
|
||||
- test
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
platform: [amd64, arm64]
|
||||
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix)}}
|
||||
steps:
|
||||
- name: Download binaries
|
||||
uses: actions/download-artifact@v3
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: binaries
|
||||
path: /tmp/ehco
|
||||
@@ -116,7 +95,7 @@ jobs:
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build multi-platform image
|
||||
uses: docker/build-push-action@v4
|
||||
uses: docker/build-push-action@v5
|
||||
id: build
|
||||
with:
|
||||
context: /tmp/ehco
|
||||
@@ -125,15 +104,17 @@ jobs:
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
|
||||
|
||||
- name: Export digest
|
||||
run: |
|
||||
mkdir -p /tmp/digests
|
||||
digest="${{ steps.build.outputs.digest }}"
|
||||
touch "/tmp/digests/${digest#sha256:}"
|
||||
|
||||
- name: Upload digest
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: digests
|
||||
name: digests-${{ matrix.platform }}
|
||||
path: /tmp/digests/*
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
@@ -141,15 +122,12 @@ jobs:
|
||||
merge:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- prepare-matrix
|
||||
- build-image
|
||||
steps:
|
||||
- name: Download digests
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: digests
|
||||
path: /tmp/digests
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
@@ -159,16 +137,36 @@ jobs:
|
||||
type=sha
|
||||
type=raw,value=latest
|
||||
type=ref,event=tag
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
# need add more platform when change the matrix
|
||||
- name: Download digests for amd64
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: digests-amd64
|
||||
path: /tmp/digests/amd64
|
||||
|
||||
- name: Download digests for arm64
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: digests-arm64
|
||||
path: /tmp/digests/arm64
|
||||
|
||||
- name: Create manifest list and push
|
||||
working-directory: /tmp/digests
|
||||
run: |
|
||||
echo "Creating manifest list..."
|
||||
AMD64_DIGEST=$(ls amd64/)
|
||||
ARM64_DIGEST=$(ls arm64/)
|
||||
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
|
||||
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
|
||||
--append ${{ env.REGISTRY_IMAGE }}@sha256:$AMD64_DIGEST \
|
||||
--append ${{ env.REGISTRY_IMAGE }}@sha256:$ARM64_DIGEST
|
||||
|
||||
- name: Inspect image
|
||||
run: |
|
||||
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
|
||||
|
||||
Reference in New Issue
Block a user