mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-10 17:52:44 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b25df2e214 | ||
|
|
5999ddbe1d | ||
|
|
7424190ee5 | ||
|
|
87e8836c78 | ||
|
|
1a7747c2d2 |
125
.github/workflows/build-docker.yml
vendored
125
.github/workflows/build-docker.yml
vendored
@@ -7,15 +7,26 @@ on:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: ghcr.io
|
REGISTRY: ghcr.io
|
||||||
IMAGE_NAME: ${{ github.repository }}
|
IMAGE_NAME: krau/saveany-bot
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: docker-build-${{ github.repository }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
prepare:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
version: ${{ steps.args.outputs.version }}
|
||||||
|
git_commit: ${{ steps.args.outputs.git_commit }}
|
||||||
|
build_time: ${{ steps.args.outputs.build_time }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -31,8 +42,28 @@ jobs:
|
|||||||
type=sha
|
type=sha
|
||||||
type=raw,value=latest
|
type=raw,value=latest
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Extract Dockerfile args
|
||||||
uses: docker/setup-qemu-action@v3
|
id: args
|
||||||
|
run: |
|
||||||
|
echo "git_commit=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "build_time=$(git show -s --format=%cI)" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
build:
|
||||||
|
needs: prepare
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
arch: [amd64, arm64]
|
||||||
|
type: [default, micro, pico]
|
||||||
|
fail-fast: false
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || 'ubuntu-24.04-arm' }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
@@ -44,71 +75,43 @@ jobs:
|
|||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Extract Dockerfile args
|
- name: Set Dockerfile path
|
||||||
id: args
|
id: dockerfile
|
||||||
run: |
|
run: |
|
||||||
echo "git_commit=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
|
if [ "${{ matrix.type }}" == "default" ]; then
|
||||||
echo "build_time=$(git show -s --format=%cI)" >> "$GITHUB_OUTPUT"
|
echo "DOCKERFILE=./Dockerfile" >> "$GITHUB_OUTPUT"
|
||||||
|
elif [ "${{ matrix.type }}" == "micro" ]; then
|
||||||
|
echo "DOCKERFILE=./Dockerfile.micro" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "DOCKERFILE=./Dockerfile.pico" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Set image tags
|
||||||
|
id: tags
|
||||||
|
run: |
|
||||||
|
if [ "${{ matrix.type }}" == "default" ]; then
|
||||||
|
TAGS="${{ needs.prepare.outputs.tags }}"
|
||||||
|
elif [ "${{ matrix.type }}" == "micro" ]; then
|
||||||
|
TAGS="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro-latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro-${{ needs.prepare.outputs.version }}"
|
||||||
|
else
|
||||||
|
TAGS="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico-latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico-${{ needs.prepare.outputs.version }}"
|
||||||
|
fi
|
||||||
|
echo "TAGS=$TAGS" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
id: build-and-push
|
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ${{ steps.dockerfile.outputs.DOCKERFILE }}
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: ${{ matrix.arch == 'amd64' && 'linux/amd64' || 'linux/arm64' }}
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.tags.outputs.TAGS }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ needs.prepare.outputs.labels }}
|
||||||
cache-from: |
|
cache-from: |
|
||||||
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.type }}-latest
|
||||||
type=gha
|
type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
build-args: |
|
build-args: |
|
||||||
VERSION=${{ steps.meta.outputs.version }}
|
VERSION=${{ needs.prepare.outputs.version }}
|
||||||
GitCommit=${{ steps.args.outputs.git_commit }}
|
GitCommit=${{ needs.prepare.outputs.git_commit }}
|
||||||
BuildTime=${{ steps.args.outputs.build_time }}
|
BuildTime=${{ needs.prepare.outputs.build_time }}
|
||||||
|
|
||||||
- name: Build and push micro Docker image
|
|
||||||
id: build-and-push-micro
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: ./Dockerfile.micro
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
|
||||||
tags: |
|
|
||||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro
|
|
||||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro-latest
|
|
||||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro-${{ steps.meta.outputs.version }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
cache-from: |
|
|
||||||
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
||||||
type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
build-args: |
|
|
||||||
VERSION=${{ steps.meta.outputs.version }}
|
|
||||||
GitCommit=${{ steps.args.outputs.git_commit }}
|
|
||||||
BuildTime=${{ steps.args.outputs.build_time }}
|
|
||||||
|
|
||||||
- name: Build and push pico Docker image
|
|
||||||
id: build-and-push-pico
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: ./Dockerfile.pico
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
|
||||||
tags: |
|
|
||||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico
|
|
||||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico-latest
|
|
||||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico-${{ steps.meta.outputs.version }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
cache-from: |
|
|
||||||
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
||||||
type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
build-args: |
|
|
||||||
VERSION=${{ steps.meta.outputs.version }}
|
|
||||||
GitCommit=${{ steps.args.outputs.git_commit }}
|
|
||||||
BuildTime=${{ steps.args.outputs.build_time }}
|
|
||||||
|
|||||||
@@ -24,13 +24,12 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
|
|||||||
-X 'github.com/krau/SaveAny-Bot/config.BuildTime=${BuildTime}' \
|
-X 'github.com/krau/SaveAny-Bot/config.BuildTime=${BuildTime}' \
|
||||||
-X 'github.com/krau/SaveAny-Bot/config.Docker=true' \
|
-X 'github.com/krau/SaveAny-Bot/config.Docker=true' \
|
||||||
" \
|
" \
|
||||||
-o saveany-bot .
|
-o saveany-bot . && chmod +x saveany-bot
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY --from=builder /app/saveany-bot .
|
COPY --from=builder /app/saveany-bot .
|
||||||
RUN chmod +x /app/saveany-bot
|
|
||||||
|
|
||||||
ENTRYPOINT ["/app/saveany-bot"]
|
ENTRYPOINT ["/app/saveany-bot"]
|
||||||
|
|||||||
Reference in New Issue
Block a user