From 42528c41ddda8eecf1f1491f61d7495b16cb180d Mon Sep 17 00:00:00 2001 From: LongYinan Date: Thu, 26 Nov 2020 14:30:19 +0800 Subject: [PATCH] chore: build codes in node:10-alpine --- .github/workflows/docker.yaml | 4 ++-- .github/workflows/linux-musl.yaml | 28 ++++++++++++++++++++-------- alpine.Dockerfile | 16 +++++++--------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 75d77064..647e68df 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -22,8 +22,8 @@ jobs: - name: Build docker image run: | - docker build . -f alpine.Dockerfile --pull --no-cache -t docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts + docker build . -f alpine.Dockerfile --pull --no-cache -t docker.pkg.github.com/napi-rs/napi-rs/nodejs-rust:10-alpine - name: Push docker image run: | - docker push docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts + docker push docker.pkg.github.com/napi-rs/napi-rs/nodejs-rust:10-alpine diff --git a/.github/workflows/linux-musl.yaml b/.github/workflows/linux-musl.yaml index 753dca8e..471e54bf 100644 --- a/.github/workflows/linux-musl.yaml +++ b/.github/workflows/linux-musl.yaml @@ -10,12 +10,24 @@ on: jobs: build: - name: stable - x86_64-unknown-linux-musl - node@14 + name: stable - x86_64-unknown-linux-musl - node@10 runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Cache cargo registry + uses: actions/cache@v1 + with: + path: ~/.cargo/registry + key: stable-${{ matrix.os }}-node-alpine-@10-${{ matrix.node }}-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache cargo index + uses: actions/cache@v1 + with: + path: ~/.cargo/git + key: stable-${{ matrix.os }}-node-alpine-@10-${{ matrix.node }}-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} + - name: Log in to registry run: | docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL @@ -26,24 +38,24 @@ jobs: - name: Pull docker image run: | - docker pull docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts - docker tag docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts builder + docker pull docker.pkg.github.com/napi-rs/napi-rs/nodejs-rust:10-alpine + docker tag docker.pkg.github.com/napi-rs/napi-rs/nodejs-rust:10-alpine builder - name: 'Install node dependencies' - run: docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder yarn + run: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/napi-rs -w /napi-rs builder yarn - name: 'Install swc musl' - run: docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder yarn add @swc/core-linux-musl --dev + run: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/napi-rs -w /napi-rs builder yarn add @swc/core-linux-musl --dev - name: 'Build TypeScript' - run: docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder yarn build + run: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/napi-rs -w /napi-rs builder yarn build - name: Run check run: | - docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder cargo check -vvv + docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/napi-rs -w /napi-rs builder cargo check -vvv - name: Unit test run: | - docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder sh -c "yarn build:test && yarn test" + docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/napi-rs -w /napi-rs builder sh -c "yarn build:test && yarn test" env: RUST_BACKTRACE: 1 diff --git a/alpine.Dockerfile b/alpine.Dockerfile index 650b574b..2fcd66d4 100644 --- a/alpine.Dockerfile +++ b/alpine.Dockerfile @@ -1,13 +1,11 @@ -FROM rust:alpine +FROM node:10-alpine -ENV RUSTFLAGS="-C target-feature=-crt-static" +ENV RUSTFLAGS="-C target-feature=-crt-static" \ + PATH="/root/.cargo/bin:$PATH" \ + CC="clang" \ + CXX="clang++" RUN sed -i -e 's/v[[:digit:]]\..*\//edge\//g' /etc/apk/repositories && \ apk update && \ - apk add nodejs yarn clang musl-dev llvm-dev curl && \ - export NODE_VERSION=$(node -e "console.log(process.version)") && \ - curl -fsSLO $(node -e "console.log(process.release.headersUrl)") && \ - tar -xf "node-$NODE_VERSION-headers.tar.gz" && \ - mv "node-$NODE_VERSION/include/node" include && \ - rm -rf "node-$NODE_VERSION" && \ - rm "node-$NODE_VERSION-headers.tar.gz" \ No newline at end of file + apk add rustup musl-dev build-base && \ + rustup-init -y