Build and push images #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and push images | |
on: | |
workflow_dispatch: | |
inputs: | |
branch: | |
required: true | |
type: string | |
default: main | |
docker_repository: | |
required: true | |
type: string | |
default: apecloud-registry.cn-zhangjiakou.cr.aliyuncs.com | |
image_tag: | |
required: true | |
type: string | |
default: apecloud/ape-dts:latest | |
platforms: | |
required: true | |
type: string | |
default: linux/arm64,linux/amd64 | |
jobs: | |
build: | |
name: Cross build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ inputs.branch }} | |
- name: Set up rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
override: true | |
- name: Install cross | |
run: cargo install cross | |
- name: Build for x86_64 | |
if: contains(inputs.platforms, 'linux/amd64') | |
run: | | |
cross build --target x86_64-unknown-linux-gnu --release | |
cp target/x86_64-unknown-linux-gnu/release/dt-main amd64-unknown-linux-gnu-dt-main | |
- name: Build for aarch64 | |
if: contains(inputs.platforms, 'linux/arm64') | |
run: | | |
cross build --target aarch64-unknown-linux-gnu --release | |
cp target/aarch64-unknown-linux-gnu/release/dt-main arm64-unknown-linux-gnu-dt-main | |
- name: Set up docker buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push docker image | |
run: | | |
docker login --username ${{ secrets.DOCKER_USER }} --password ${{ secrets.DOCKER_PASSWORD }} ${{ inputs.docker_repository }} | |
docker buildx build -f Dockerfile.github.workflow --platform ${{ inputs.platforms }} --tag ${{ inputs.docker_repository }}/${{ inputs.image_tag }} --push . |