From 03bade6feb630e5c765e8565f9e337a07ff7a451 Mon Sep 17 00:00:00 2001 From: jcs47 <11947034+jcs47@users.noreply.github.com> Date: Sat, 2 Dec 2023 01:32:15 +0000 Subject: [PATCH] chore: enable cgo (#2039) --- .../build-docker-image-and-binaries.yaml | 19 ++++- .../workflows/build-docker-image-rosetta.yaml | 72 ------------------- .../workflows/build-latest-docker-image.yaml | 22 ++++-- Dockerfile | 6 +- Dockerfile.binaries | 6 +- Dockerfile.debug | 5 +- Makefile | 3 + 7 files changed, 47 insertions(+), 86 deletions(-) delete mode 100644 .github/workflows/build-docker-image-rosetta.yaml diff --git a/.github/workflows/build-docker-image-and-binaries.yaml b/.github/workflows/build-docker-image-and-binaries.yaml index b70870ba3..cfe4a46b1 100644 --- a/.github/workflows/build-docker-image-and-binaries.yaml +++ b/.github/workflows/build-docker-image-and-binaries.yaml @@ -7,7 +7,14 @@ on: description: Github tag to release binaries for (reusing an existing tag will make the pipeline fail) required: true default: latest - + cgo: + description: Whether to enable cgo ("true"/"false") + required: true + default: "true" + wasm: + description: Whether to enable wasm ("true"/"false") + required: true + default: "true" jobs: release-binaries: runs-on: ${{ matrix.os }} @@ -64,7 +71,12 @@ jobs: ARCH: ${{ matrix.arch }} OS_TYPE: ${{ matrix.os }} SEMVER: ${{ github.event.inputs.tag }} + WASM: ${{ github.event.inputs.WASM }} + CGO_ENABLED: 0 run: | + if [ "${{ github.event.inputs.cgo }}" == "true" ]; then + export CGO_ENABLED=1 + fi OS=$(echo "$OS_TYPE" | sed -e 's/ubuntu-20.04/linux/; s/macos-latest/darwin/') make build-binaries-multiarch mv ./bin/axelard ./bin/axelard-"$OS"-"$ARCH"-"$SEMVER" @@ -166,10 +178,15 @@ jobs: - name: Build and push docker images run: | + if [ "${{ github.event.inputs.cgo }}" == "true" ]; then + export CGO_ENABLED=1 + fi make build-push-docker-images env: PLATFORM: ${{ matrix.platform }} SEMVER: ${{ github.event.inputs.tag }} + WASM: ${{ github.event.inputs.wasm }} + CGO_ENABLED: 0 combine-sign: diff --git a/.github/workflows/build-docker-image-rosetta.yaml b/.github/workflows/build-docker-image-rosetta.yaml deleted file mode 100644 index bc2877e0e..000000000 --- a/.github/workflows/build-docker-image-rosetta.yaml +++ /dev/null @@ -1,72 +0,0 @@ -name: Build and push rosetta docker image - -on: - workflow_dispatch: - inputs: - tag: - description: Github tag to release binaries for (reusing an existing tag will make the pipeline fail) - required: true - default: latest - -jobs: - release: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-20.04] - arch: [amd64] - - permissions: - contents: write - packages: write - id-token: write - - steps: - - - name: Validate tag - env: - SEMVER: ${{ github.event.inputs.tag }} - run: | - if [[ $SEMVER =~ v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\-rosetta ]]; then echo "Tag is okay" && exit 0; else echo "invalid tag" && exit 1; fi - - - name: Checkout code - uses: actions/checkout@v2 - with: - fetch-depth: '0' - ref: ${{ github.event.inputs.tag }} - submodules: recursive - - - name: Install Cosign - uses: sigstore/cosign-installer@main - - - name: Set up ssh agent - uses: webfactory/ssh-agent@v0.5.2 - with: - ssh-private-key: ${{ secrets.CICD_RSA_KEY }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - with: - config: .github/buildkit-config.toml - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_TOKEN }} - - - name: Build and push docker image rosetta - run: | - make build-push-docker-images-rosetta - env: - SEMVER: ${{ github.event.inputs.tag }} - - - name: Sign the images with GitHub OIDC - run: cosign sign --oidc-issuer https://token.actions.githubusercontent.com ${TAGS} - env: - TAGS: axelarnet/axelar-core:${{ github.event.inputs.tag }}-rosetta - COSIGN_EXPERIMENTAL: 1 diff --git a/.github/workflows/build-latest-docker-image.yaml b/.github/workflows/build-latest-docker-image.yaml index d50535e11..6f48b97ce 100644 --- a/.github/workflows/build-latest-docker-image.yaml +++ b/.github/workflows/build-latest-docker-image.yaml @@ -10,10 +10,14 @@ on: description: Whether or build the debug image ("true"/"false") required: true default: "false" + cgo: + description: Whether to enable cgo ("true"/"false") + required: true + default: "true" wasm: description: Whether to enable wasm ("true"/"false") required: true - default: "false" + default: "true" jobs: build-and-push-latest-docker-image: @@ -47,9 +51,13 @@ jobs: - name: Build docker image (normal) env: - WASM: ${{ github.event.inputs.WASM }} + WASM: ${{ github.event.inputs.wasm }} + CGO_ENABLED: 0 run: | - make WASM="${WASM}" docker-image + if [ "${{ github.event.inputs.cgo }}" == "true" ]; then + export CGO_ENABLED=1 + fi + make docker-image - name: Push to ECR (normal) env: @@ -63,9 +71,13 @@ jobs: - name: Build docker image (debug) if: github.event.inputs.buildDebug != 'false' env: - WASM: ${{ github.event.inputs.WASM }} + WASM: ${{ github.event.inputs.wasm }} + CGO_ENABLED: 0 run: | - make WASM="${WASM}" docker-image-debug + if [ "${{ github.event.inputs.cgo }}" == "true" ]; then + export CGO_ENABLED=1 + fi + make docker-image-debug - name: Push to ECR (debug) if: github.event.inputs.buildDebug != 'false' diff --git a/Dockerfile b/Dockerfile index 1f06ec7dc..b83010189 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM golang:1.21-alpine3.18 as build ARG ARCH=x86_64 -ARG WASM=false +ARG WASM=true RUN apk add --no-cache --update \ ca-certificates \ @@ -30,8 +30,8 @@ RUN if [[ "${WASM}" == "true" ]]; then \ COPY . . -ENV CGO_ENABLED=0 -RUN make WASM="${WASM}" MUSLC="${WASM}" build +ENV CGO_ENABLED=1 +RUN make MUSLC="${WASM}" build FROM alpine:3.18 diff --git a/Dockerfile.binaries b/Dockerfile.binaries index f58cc7de8..0f257caa6 100644 --- a/Dockerfile.binaries +++ b/Dockerfile.binaries @@ -7,12 +7,12 @@ RUN apt update && apt install \ WORKDIR $GOPATH/src/github.com/axelarnetwork/axelar-core ARG SEMVER -ARG WASM=false +ARG WASM=true COPY ./go.mod . COPY ./go.sum . RUN go mod download COPY . . -ENV CGO_ENABLED=0 -RUN make WASM="${WASM}" build-binaries +ENV CGO_ENABLED=1 +RUN make build-binaries diff --git a/Dockerfile.debug b/Dockerfile.debug index aca5bce16..7579053a0 100644 --- a/Dockerfile.debug +++ b/Dockerfile.debug @@ -5,7 +5,7 @@ RUN groupadd -r -g 1001 axelard && useradd -m -r -u 1000 -g axelard axelard WORKDIR /axelar RUN chown -R axelard:axelard /axelar -ARG WASM=false +ARG WASM=true RUN go install github.com/go-delve/delve/cmd/dlv@latest @@ -15,7 +15,8 @@ RUN go mod download COPY . . RUN git config --global --add safe.directory /axelar -RUN make WASM="${WASM}" debug +ENV CGO_ENABLED=1 +RUN make debug RUN cp /axelar/bin/* /usr/local/bin # The home directory of axelar-core where configuration/genesis/data are stored diff --git a/Makefile b/Makefile index 0a96bf383..2f4c875f3 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,9 @@ DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bu HTTPS_GIT := https://github.com/axelarnetwork/axelar-core.git PUSH_DOCKER_IMAGE := true +$(info $$WASM is [${WASM}]) +$(info $$CGO_ENABLED is [${CGO_ENABLED}]) + ifeq ($(WASM), true) WASM_ENABLED := "true" ifndef $(WASM_CAPABILITIES)