From 6d1fcda1f25930afd3143835f83fcfe271433931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Bernard?= Date: Tue, 13 Jun 2023 20:18:16 +0200 Subject: [PATCH] build: integration with GitHub Actions --- .github/workflows/release.yml | 119 +++++++++++++++++++++++++++ .github/workflows/tag.yml | 27 ++++++ .github/workflows/test.yml | 80 ++++++++++++++++++ Cargo.lock | 11 +++ offchain-resolver-gateway/Cargo.toml | 2 + offchain-resolver-gateway/Dockerfile | 20 +++++ 6 files changed, 259 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/tag.yml create mode 100644 .github/workflows/test.yml create mode 100644 offchain-resolver-gateway/Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3c874da --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,119 @@ +name: "Release" + +permissions: + contents: "write" + +on: + workflow_run: + workflows: ["Tag"] + types: + - "completed" + +jobs: + get-tag: + name: "Get Tag From Package Version" + runs-on: "ubuntu-latest" + outputs: + pkg-version: ${{ steps.pkg-version.outputs.PKG_VERSION }} + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + with: + token: ${{ github.token }} + + - name: "Get tag" + id: "pkg-version" + shell: "bash" + run: | + echo PKG_VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/["]/, "", $2); printf("%s",$2) }' offchain-resolver-gateway/Cargo.toml) >> $GITHUB_OUTPUT + + create-release: + name: "Create release" + if: ${{ github.event.workflow_run.conclusion == 'success' }} + needs: "get-tag" + runs-on: "ubuntu-latest" + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + + - name: "Create release" + uses: "taiki-e/create-gh-release-action@v1" + with: + # (optional) Path to changelog. + # changelog: CHANGELOG.md + branch: "main" + ref: refs/tags/v${{ needs.get-tag.outputs.pkg-version }} + token: ${{ github.token }} + + upload-assets: + name: "Upload assets to Github releases" + if: ${{ github.event.workflow_run.conclusion == 'success' }} + needs: + - "get-tag" + - "create-release" + strategy: + matrix: + include: + - target: "x86_64-unknown-linux-gnu" + os: "ubuntu-latest" + - target: "x86_64-unknown-linux-musl" + os: "ubuntu-latest" + - target: x86_64-apple-darwin + os: macOS-11 + macosx_deployment_target: 10.13 + developer_dir: /Applications/Xcode_11.7.app + sdkroot: /Applications/Xcode_11.7.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk + - target: aarch64-apple-darwin + os: macOS-11 + macosx_deployment_target: 11.0 + developer_dir: /Applications/Xcode_13.2.1.app + sdkroot: /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk + # Windows build not working due to OpenSSL :( + # error: failed to run custom build command for `openssl-sys v0.9.88` + #- target: x86_64-pc-windows-msvc + # os: windows-2019 + # rustflags: -Ctarget-feature=+crt-static + runs-on: ${{ matrix.os }} + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + + - name: "Upload Binaries" + uses: "taiki-e/upload-rust-binary-action@v1" + with: + bin: "offchain-resolver-gateway" + target: ${{ matrix.target }} + archive: $bin-${{ matrix.target }} + ref: refs/tags/v${{ needs.get-tag.outputs.pkg-version }} + token: ${{ github.token }} + + push-to-registry: + name: "Push Docker image to Docker Hub" + if: ${{ github.event.workflow_run.conclusion == 'success' }} + needs: + - "get-tag" + - "upload-assets" + runs-on: "ubuntu-latest" + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + + - name: "Log in to Docker Hub" + uses: "docker/login-action@v2" + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: "Extract metadata (tags, labels) for Docker" + id: "meta" + uses: "docker/metadata-action@v4" + with: + images: "jeje/ens-offchain-resolver-gateway-rs" + + - name: "Build and push Docker image" + uses: "docker/build-push-action@v3" + with: + context: offchain-resolver-gateway + push: true + tags: ens-offchain-resolver-gateway-rs:latest,ens-offchain-resolver-gateway-rs:v${{ needs.get-tag.outputs.pkg-version }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..035a81a --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,27 @@ +name: "Tag" + +on: + push: + branches: + - "main" + +jobs: + create-tag: + name: "Create tag" + runs-on: "ubuntu-latest" + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + with: + token: ${{ github.token }} + + - name: "Get tag" + id: "get-tag" + shell: "bash" + run: | + echo PKG_VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/["]/, "", $2); printf("%s",$2) }' offchain-resolver-gateway/Cargo.toml) >> $GITHUB_OUTPUT + + - name: "Set Tag" + shell: "bash" + run: | + git tag v${{ steps.get-tag.outputs.PKG_VERSION }} && git push --tags diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..05f3a94 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,80 @@ +name: "Test" +on: [push, pull_request] + +#on: +# pull_request: + +jobs: + check: + name: "Cargo check" + runs-on: "ubuntu-latest" + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + + - uses: "actions-rs/toolchain@v1" + with: + profile: "minimal" + toolchain: "stable" + override: true + + - uses: "actions-rs/cargo@v1" + with: + command: "check" + + test: + name: "Cargo test" + runs-on: "ubuntu-latest" + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + + - uses: "actions-rs/toolchain@v1" + with: + profile: "minimal" + toolchain: "stable" + override: true + + - uses: "actions-rs/cargo@v1" + with: + command: "test" + + fmt: + name: "Cargo format" + runs-on: "ubuntu-latest" + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + + - uses: "actions-rs/toolchain@v1" + with: + profile: "minimal" + toolchain: "stable" + override: true + + - run: "rustup component add rustfmt" + + - uses: "actions-rs/cargo@v1" + with: + command: "fmt" + args: "--all -- --check" + + clippy: + name: "Cargo clippy" + runs-on: "ubuntu-latest" + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + + - uses: "actions-rs/toolchain@v1" + with: + profile: "minimal" + toolchain: "stable" + override: true + + - run: "rustup component add clippy" + + - uses: "actions-rs/cargo@v1" + with: + command: "clippy" + args: "-- -D warnings" \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 5b66ced..f89a141 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2112,6 +2112,7 @@ dependencies = [ "ethers", "ethers-ccip-read", "eyre", + "openssl", "serde", "serde_json", "thiserror", @@ -2189,6 +2190,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "111.26.0+1.1.1u" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efc62c9f12b22b8f5208c23a7200a442b2e5999f8bdf80233852122b5a4f6f37" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.88" @@ -2197,6 +2207,7 @@ checksum = "c2ce0f250f34a308dcfdbb351f511359857d4ed2134ba715a4eadd46e1ffd617" dependencies = [ "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] diff --git a/offchain-resolver-gateway/Cargo.toml b/offchain-resolver-gateway/Cargo.toml index 56b3323..2873b2f 100644 --- a/offchain-resolver-gateway/Cargo.toml +++ b/offchain-resolver-gateway/Cargo.toml @@ -23,5 +23,7 @@ thiserror = "1.0.40" async-trait = "0.1.68" clap = { version = "4.3.3", features = ["color", "error-context", "help", "std", "suggestions", "usage", "cargo", "env"] } +openssl = { version = "0.10", features = ["vendored"] } + [dev-dependencies] ethers-ccip-read = "0.1.1" diff --git a/offchain-resolver-gateway/Dockerfile b/offchain-resolver-gateway/Dockerfile new file mode 100644 index 0000000..4bc78fa --- /dev/null +++ b/offchain-resolver-gateway/Dockerfile @@ -0,0 +1,20 @@ +FROM alpine:3.16.2 as builder + +WORKDIR /opt/ + +RUN apk add curl protoc musl-dev gzip git + +# offchain-resolver-gateway +RUN curl -sLO https://github.com/jeje/ens-offchain-resolver-gateway-rs/releases/latest/download/offchain-resolver-gateway-x86_64-unknown-linux-musl.tar.gz \ + && tar -xvf offchain-resolver-gateway-x86_64-unknown-linux-musl.tar.gz \ + && chmod +x offchain-resolver-gateway + +######################################################### + +FROM alpine:3.16.2 + +RUN apk add tmux + +COPY --from=builder /opt/offchain-resolver-gateway /opt/offchain-resolver-gateway + +RUN chown -R root:root /opt/ \ No newline at end of file