Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: build binary #483

158 changes: 158 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: 2.1
orbs:
docker-buildx: sensu/docker-buildx@1.1.1
aws-ecr: circleci/aws-ecr@8.1.2
win: circleci/windows@5.0

executors:
docker-rust:
Expand Down Expand Up @@ -97,6 +98,29 @@ commands:
command: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
sudo apt update && sudo apt install -y libssl1.1
make-artifact:
parameters:
target:
description: "Rust target to put in artifact"
type: string
suffix:
description: "Suffix that is on the binary"
type: string
default: ""
steps:
- run:
name: Make artifact
command: |
mkdir shuttle
mv target/<< parameters.target >>/release/cargo-shuttle<< parameters.suffix >> shuttle/cargo-shuttle<< parameters.suffix >>
mv LICENSE shuttle/
mv README.md shuttle/
mkdir artifacts
tar -cvzf artifacts/cargo-shuttle-${CIRCLE_TAG}-<< parameters.target >>.tar.gz shuttle
- persist_to_workspace:
root: artifacts
paths:
- cargo-shuttle-${CIRCLE_TAG}-<< parameters.target >>.tar.gz

jobs:
workspace-fmt:
Expand Down Expand Up @@ -239,6 +263,89 @@ jobs:
command: |
PUSH=true PLATFORMS=linux/amd64 make images
- save-buildx-cache
build-binaries-linux:
machine:
image: << parameters.image >>
resource_class: << parameters.resource_class >>
parameters:
target:
description: "Linux target to build for"
type: string
image:
description: "Machine image to use"
type: string
resource_class:
description: "The resource type to use for the machine"
type: string
steps:
- checkout
- run: sudo apt update && sudo DEBIAN_FRONTEND=noninteractive apt install -y libssl-dev musl-tools clang
- run:
name: Install Rust
command: curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | bash -s -- -y --default-toolchain 1.63.0 --target << parameters.target >>
- run:
name: Build
command: |
# From https://github.com/briansmith/ring/issues/1414#issuecomment-1055177218
export CC_aarch64_unknown_linux_musl=clang
# "vendored-openssl" is from https://github.com/cross-rs/cross/issues/229#issuecomment-597898074
cargo build --release --package cargo-shuttle --features vendored-openssl --target << parameters.target >>
- make-artifact:
target: << parameters.target >>
build-binaries-windows:
executor:
name: win/server-2022
size: medium
environment:
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
steps:
- checkout
- run: choco install -y strawberryperl
- run:
name: Install Rust
command: |
wget -OutFile "C:\rustup-init.exe" https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe
C:\rustup-init.exe -y --default-toolchain 1.63.0 --target x86_64-pc-windows-msvc
- run:
name: Build
command: |
# From https://github.com/alexcrichton/openssl-src-rs/issues/45
# Because of https://github.com/openssl/openssl/issues/9048
$env:OPENSSL_SRC_PERL="C:\Strawberry\perl\bin\perl.exe"
# "vendored-openssl" is from https://github.com/cross-rs/cross/issues/229#issuecomment-597898074
..\.cargo\bin\cargo.exe build --release --package cargo-shuttle --features vendored-openssl --target x86_64-pc-windows-msvc
- make-artifact:
target: x86_64-pc-windows-msvc
suffix: ".exe"
build-binaries-mac:
macos:
xcode: 12.5.1
resource_class: medium
steps:
- checkout
- run:
name: Install Rust
command: curl --proto '=https' https://sh.rustup.rs -sSf | bash -s -- -y --default-toolchain 1.63.0 --target x86_64-apple-darwin
- run:
name: Build
command: |
# "vendored-openssl" is from https://github.com/cross-rs/cross/issues/229#issuecomment-597898074
cargo build --release --package cargo-shuttle --features vendored-openssl --target x86_64-apple-darwin
- make-artifact:
target: x86_64-apple-darwin
publish-github-release:
docker:
- image: cimg/go:1.19.3
steps:
- attach_workspace:
at: artifacts
- run:
name: "Publish Release on GitHub"
environment:
GITHUB_TOKEN: $GITHUB_TOKEN
command: |
go install github.com/tcnksm/ghr@v0.16.0
ghr -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete -draft ${CIRCLE_TAG} artifacts/

workflows:
version: 2
Expand Down Expand Up @@ -283,3 +390,54 @@ workflows:
filters:
branches:
only: production
- build-binaries-linux:
name: build-binaries-x86_64
image: ubuntu-2204:2022.04.1
target: x86_64-unknown-linux-musl
resource_class: medium
requires:
- build-and-push
filters:
tags:
only: /^v.*/
branches:
only: production
- build-binaries-linux:
name: build-binaries-aarch64
image: ubuntu-2004:202101-01
target: aarch64-unknown-linux-musl
resource_class: arm.medium
requires:
- build-and-push
filters:
tags:
only: /^v.*/
branches:
only: production
- build-binaries-windows:
requires:
- build-and-push
filters:
tags:
only: /^v.*/
branches:
only: production
- build-binaries-mac:
requires:
- build-and-push
filters:
tags:
only: /^v.*/
branches:
only: production
- publish-github-release:
requires:
- build-binaries-x86_64
- build-binaries-aarch64
- build-binaries-windows
- build-binaries-mac
filters:
tags:
only: /^v.*/
branches:
only: production
4 changes: 4 additions & 0 deletions cargo-shuttle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ futures = "0.3.23"
headers = "0.3.8"
indoc = "1.0.7"
log = "0.4.17"
openssl = { version = '0.10', optional = true }
portpicker = "0.1.1"
reqwest = { version = "0.11.11", features = ["json"] }
reqwest-middleware = "0.1.6"
Expand Down Expand Up @@ -55,6 +56,9 @@ version = "0.7.2"
path = "../service"
features = ["loader"]

[features]
vendored-openssl = ["openssl/vendored"]

[dev-dependencies]
tempfile = "3.3.0"
test-context = "0.1.4"
Expand Down