diff --git a/.github/workflows/etcdcluster.yaml b/.github/workflows/etcdcluster.yaml index 3dd39e8..35c8b4a 100644 --- a/.github/workflows/etcdcluster.yaml +++ b/.github/workflows/etcdcluster.yaml @@ -1,5 +1,4 @@ name: etcdcluster - permissions: contents: read @@ -7,18 +6,48 @@ on: push: branches: [ etcdcluster ] workflow_dispatch: - + inputs: + branch: + description: 'branch' + required: true + default: 'main' + tag: + description: 'image tag' + required: false + default: '' env: + REPO: yylt/etcdauto + PROJECT: etcdauto + BRANCH: main Dockerfile: Dockerfile-etcdcluster - REGISTRY_NAME: "docker.io" - REGISTRY_USER: "${{ secrets.DOCKER_HUB_USER }}" - REGISTRY_PASS: "${{ secrets.DOCKER_HUB_PASSWORD }}" + REGISTRY_NAME: "${{ secrets.MY_HUB_NAME }}" + REGISTRY_USER: "${{ secrets.MY_HUB_USER }}" + REGISTRY_PASS: "${{ secrets.MY_HUB_PASSWORD }}" + BUILDX_NO_DEFAULT_ATTESTATIONS: 1 jobs: build: name: Build runs-on: ubuntu-latest #[self-hosted, linux, x64] steps: + + - name: Getting image tag + id: tag + run: | + echo "trigger by ${{ github.event_name }}" + echo "sha256 is ${{ github.sha }}" + + if ${{ github.event_name == 'workflow_dispatch' }} ; then + echo "vbranch=${{ github.event.inputs.branch }}" >> $GITHUB_ENV + if [ "${{ github.event.inputs.tag }}" != "" ] ; then + echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_ENV + else + echo "tag=${{ github.event.inputs.branch }}" >> $GITHUB_ENV + fi + else + echo "vbranch=${{ env.BRANCH }}" >> $GITHUB_ENV + echo "tag=${{ env.BRANCH }}" >> $GITHUB_ENV + fi - uses: actions/checkout@v4 - uses: ./.github/actions/setup - name: Login to Registry @@ -28,13 +57,19 @@ jobs: username: ${{ env.REGISTRY_USER }} password: ${{ env.REGISTRY_PASS }} + - name: Check out build code + uses: actions/checkout@v4 + with: + repository: ${{ env.REPO }} + ref: ${{ env.vbranch }} + path: ${{ env.PROJECT }} + - name: Docker Image Build And Push run: | + cd ${{ env.PROJECT }} docker buildx build --no-cache \ --platform linux/amd64,linux/arm64 \ --provenance false --sbom false \ --output "type=image,push=true" \ - --tag ${{ env.REGISTRY_NAME }}/yylt/etcdcluster:${{ env.date }} \ - --tag ${{ env.REGISTRY_NAME }}/yylt/etcdcluster:latest \ - --file ./${{ env.Dockerfile }} . - + --tag ${{ env.REGISTRY_NAME }}/multiarch/etcdcluster:${{ env.tag }} \ + --file ../${{ env.Dockerfile }} . diff --git a/Dockerfile-etcdcluster b/Dockerfile-etcdcluster index 2615e00..60e4452 100644 --- a/Dockerfile-etcdcluster +++ b/Dockerfile-etcdcluster @@ -1,6 +1,7 @@ -ARG ETCD_IMAGE=gcr.io/etcd-development/etcd:v3.5.21 +# syntax = docker/dockerfile:1.4 +ARG ETCD_IMAGE=gcr.io/etcd-development/etcd:v3.5.26 -FROM --platform=$BUILDPLATFORM golang:1.25-trixie AS builder +FROM --platform=$BUILDPLATFORM golang:1.25 AS builder ARG TARGETOS ARG TARGETARCH @@ -8,23 +9,30 @@ ARG TARGETPLATFORM WORKDIR / -COPY source source +COPY . . -RUN GOARCH=${TARGETARCH} make -C /source/etcdcluster build +ENV GOARCH=${TARGETARCH} + +RUN BUILD_PLATFORMS=${TARGETPLATFORM} make build FROM ${ETCD_IMAGE} as ETCD -FROM debian:13-slim +FROM debian:12-slim ARG TARGETPLATFORM USER root -COPY --from=builder /source/etcdcluster/bin/${TARGETPLATFORM}/etcdcluster /usr/bin/ +COPY --from=builder /bin/${TARGETPLATFORM}/etcdcluster /usr/bin/ +COPY --from=builder /bin/${TARGETPLATFORM}/ecsnode /usr/bin/ COPY --from=ETCD /usr/local/bin/etcd /usr/bin/ COPY --from=ETCD /usr/local/bin/etcdctl /usr/bin/ RUN apt-get update && \ - apt-get install -y --no-install-recommends golang-cfssl && \ + apt-get install -y --no-install-recommends golang-cfssl dumb-init iproute2 curl && \ rm -rf /var/lib/apt/lists/* + +USER 65532:65532 +ENTRYPOINT ["etcdcluster"] +