Skip to content

Update test project and "fix" problem #1

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
## Usage

```sh
./build_and_test <Rust version>
./build <Rust version>
./test
```

- `<Rust version>`: The Rust version is the version of the [Rust language](https://rust-lang.org/) to test against. It will automatically install it.
- `./build`
- Builds the Rust library.
- `<Rust version>`: The Rust version is the version of the [Rust language](https://rust-lang.org/) to test against. It will automatically install it.
- `./test`
- Load the Rust library into the Elixir app and test it.

This testing tool will follow the process described in "Build and test process details" below. Afterwards it will open a shell in which the user can do additional debugging, such as:

Expand All @@ -19,16 +24,16 @@ cat lib/elixir_package-0.0.1/install.log # Print install log file with error (if
### Examples

```sh
./build_and_test 1.20.0
./build 1.20.0 && ./test
# Works, creates a build and complains about a missing install.log file, which is fine

./build_and_test 1.21.0
./build 1.21.0 && ./test
# Fails, starts app but prints the error listed below

./build_and_test 1.29.1
./build 1.29.1 && ./test
# Fails, unrelated error that's already fixed in the latest nightly

./build_and_test nightly-2018-10-08
./build nightly-2018-10-08 && ./test
# Fails, starts app but prints the error listed below
```

Expand Down
16 changes: 0 additions & 16 deletions build_and_test → build
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ else
exit 1
fi

BUILD_VERSION=$(date -u +"0.0.%s")
TARGET_TRIPLE=x86_64-unknown-linux-musl

echo
Expand All @@ -23,9 +22,6 @@ echo "Creating build machine."
vagrant up cross
)

rm -rf build
mkdir build

echo
echo "Building Rust extension."
(
Expand All @@ -35,15 +31,3 @@ echo "Building Rust extension."

rm -f elixir_app/elixir_package/c_src/libelixir_package_extension.a
cp rust_lib/target/$TARGET_TRIPLE/release/libelixir_package_extension.a elixir_app/elixir_package/c_src

echo
echo "Building and running Elixir app release."
(
cd elixir_app
# Build docker image with Elixir app in a two stage setup
# First stage compiles the app
# Second stage only runs the app
docker build --build-arg BUILD_VERSION=$BUILD_VERSION -t alpine-elixir-build-test:build .
# Run the Elixir app
docker run -e BUILD_VERSION=$BUILD_VERSION -it --rm alpine-elixir-build-test:build ash
)
8 changes: 3 additions & 5 deletions elixir_app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# First build stage
# This will compile and package the app as a release
FROM bitwalker/alpine-elixir:1.7.3 AS builder
ARG BUILD_VERSION

ENV HOME=/app \
TERM=xterm\
Expand All @@ -25,6 +24,7 @@ RUN apk update && \
mix do local.hex --force && \
mix do local.rebar --force

ARG BUILD_VERSION
COPY elixir_package elixir_package
COPY mix.exs mix.exs
COPY mix.lock mix.lock
Expand All @@ -44,7 +44,6 @@ RUN rm -rf ${HOME}
# Second build stage
# This image doesn't have the build dependencies installed
FROM bitwalker/alpine-elixir:1.7.3
ARG BUILD_VERSION

ENV PROJECT_NAME=elixir_app \
HOME=/app \
Expand All @@ -53,15 +52,14 @@ ENV PROJECT_NAME=elixir_app \
WORKDIR ${HOME}

RUN mkdir -p ${HOME}
# Add useful tools
RUN apk add --update screen curl

ARG BUILD_VERSION
COPY --from=builder /build.tar.gz ${HOME}/build.tar.gz

RUN tar -zxvf build.tar.gz; rm build.tar.gz

WORKDIR ${HOME}
# Add a convenience run script that opens a console after starting the app
RUN printf "#!/bin/ash\n./bin/elixir_app start; sleep 5; cat lib/elixir_package-0.0.1/install.log; ash" > ${HOME}/run && chmod +x ${HOME}/run
RUN printf "#!/bin/ash\n./bin/elixir_app foreground &\nsleep 5\ncat lib/elixir_package-0.0.1/install.log; ash" > ${HOME}/run && chmod +x ${HOME}/run

ENTRYPOINT ["./run"]
2 changes: 1 addition & 1 deletion elixir_app/elixir_package/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ LIB_NAME = libelixir_package_extension.a
ERLANG_PATH = $(shell erl -eval 'io:format("~s", [lists:concat([code:root_dir(), "/erts-", erlang:system_info(version), "/include"])])' -s init stop -noshell)
CFLAGS = -g -O3 -pedantic -Wall -Wextra -I"$(ERLANG_PATH)" -I"$(LIB_DIR)"
ifeq ($(shell uname),Linux)
LDFLAGS = -Wl,--whole-archive "$(LIB_DIR)"/$(LIB_NAME) -Wl,--no-whole-archive
LDFLAGS = -Wl,--whole-archive "$(LIB_DIR)"/$(LIB_NAME) -Wl,--no-whole-archive -static-libgcc
else
LDFLAGS = "$(LIB_DIR)"/$(LIB_NAME)
endif
Expand Down
17 changes: 17 additions & 0 deletions test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -eu

BUILD_VERSION=$(date -u +"0.0.%s")

echo
echo "Building and running Elixir app release."
(
cd elixir_app
# Build docker image with Elixir app in a two stage setup
# First stage compiles the app
# Second stage only runs the app
docker build -f Dockerfile.gnu --build-arg BUILD_VERSION=$BUILD_VERSION -t elixir-build-test:build .
# Run the Elixir app
docker run -e BUILD_VERSION=$BUILD_VERSION -it --rm elixir-build-test:build ash
)