Skip to content

Commit

Permalink
容器化变更
Browse files Browse the repository at this point in the history
增加 Dockerfile 及 github action 配置

自动构建 zh 及 en 两种语言的 arm64 及 aarch64 版本的镜像
  • Loading branch information
Sense T authored and iovxw committed Oct 16, 2023
1 parent 7aedf14 commit acdca6a
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Package Image

on:
push:
tags:
- 'v*'

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@7e0881f8fe90b25e305bbf0309761e9314607e25
with:
cosign-release: 'v1.9.0'

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image - Chinese
id: build-and-push-zh
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
build-args: LOCALE=zh
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:zh,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:zh-${{ github.ref_name }}
platforms: linux/amd64,linux/arm64

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image - English
id: build-and-push-en
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
build-args: LOCALE=en
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:en,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:en-${{ github.ref_name }}
platforms: linux/amd64,linux/arm64
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM alpine as build

ARG LOCALE=zh

ENV RUSTFLAGS="-C target-feature=-crt-static" LOCALE=${LOCALE}
WORKDIR /usr/src/rssbot
COPY . .
RUN apk add --no-cache rustup openssl-dev build-base && rustup-init -y --default-toolchain nightly && source ${HOME}/.cargo/env && cargo build --release

FROM alpine

RUN apk add --no-cache ca-certificates openssl libgcc
ENTRYPOINT [ "/rssbot" ]

COPY --from=build /usr/src/rssbot/target/release/rssbot ./

0 comments on commit acdca6a

Please sign in to comment.