diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f4b1198 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git +.github diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b7b1859 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,67 @@ +FROM rust:1.35.0-slim + +LABEL name="rust-musl-builder" +LABEL version="1.0.0" +LABEL repository="https://github.com/juankaram/rust-musl-action" +LABEL homepage="https://github.com/juankaram/rust-musl-action" +LABEL maintainer="Juan Karam" + +LABEL com.github.actions.name="Rust MUSL Builder" +LABEL com.github.actions.description="Provides a Rust MUSL environment" +LABEL com.github.actions.icon="settings" +LABEL com.github.actions.color="orange" + +RUN apt-get update && apt-get install -y zip build-essential musl-tools pkg-config libssl-dev + +ENV BUILD_DIR=/build \ + OUTPUT_DIR=/output \ + RUST_BACKTRACE=1 \ + RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH \ + PREFIX=/toolchain \ + MUSL_VERSION=1.1.22 \ + OPENSSL_VERSION=1.1.0k \ + BUILD_TARGET=x86_64-unknown-linux-musl + +RUN mkdir -p /usr/local/cargo/bin \ + && mkdir -p $BUILD_DIR \ + && mkdir -p $OUTPUT_DIR \ + && mkdir -p $PREFIX + +WORKDIR $PREFIX + +ADD http://www.musl-libc.org/releases/musl-$MUSL_VERSION.tar.gz . +RUN tar -xvzf musl-$MUSL_VERSION.tar.gz \ + && cd musl-$MUSL_VERSION \ + && ./configure --prefix=$PREFIX \ + && make install \ + && cd .. + +ENV CC=$PREFIX/bin/musl-gcc \ + C_INCLUDE_PATH=$PREFIX/include/ \ + CPPFLAGS=-I$PREFIX/include \ + LDFLAGS=-L$PREFIX/lib + +ADD https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz . + +RUN echo "Building OpenSSL" \ + && tar -xzf "openssl-$OPENSSL_VERSION.tar.gz" \ + && cd openssl-$OPENSSL_VERSION \ + && ./Configure no-async no-afalgeng no-shared no-zlib -fPIC --prefix=$PREFIX --openssldir=$PREFIX/ssl linux-x86_64 \ + && make depend \ + && make install + +ENV OPENSSL_DIR=$PREFIX \ + OPENSSL_STATIC=true + +WORKDIR $BUILD_DIR + +RUN rustup self update && rustup update +RUN rustup target add $BUILD_TARGET +RUN rustup component add clippy-preview +RUN rustup component add rustfmt-preview +RUN cargo install cargo-release + +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7d0d6a7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ + +The MIT License (MIT) + +Copyright (c) 2018 Juan Karam, GitHub, Inc. and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a625c2b --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# GitHub Action for Rust and MUSL + +Action provides an environment with Rust, MUSL and x86_64-unknown-linux-musl target. + +## Usage + +To compile a rust binary/library with x86_64-unknown-linux-musl target: + +```hcl +action "build" { + env = { + BUILD_TARGET = "x86_64-unknown-linux-musl" + } + uses = "juankaram/rust-musl-action@master" + args = "cargo build --target $BUILD_TARGET --release" +} +``` + +## Attribution + +Heavily inspired by [GitHub Actions](https://github.com/actions), [Rust Action](https://github.com/icepuma/rust-action) and [David Lewis Work](https://github.com/davidarmstronglewis). + +## License + +The Dockerfile and associated scripts and documentation in this project are released under the [MIT License](LICENSE). + diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..4ceb075 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e -u -o pipefail +cd $GITHUB_WORKSPACE +bash -c "$*"