Skip to content

Instantly share code, notes, and snippets.

@rogeruiz
Last active June 3, 2021 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogeruiz/829516010b42962a2e4c5097b4f6caa1 to your computer and use it in GitHub Desktop.
Save rogeruiz/829516010b42962a2e4c5097b4f6caa1 to your computer and use it in GitHub Desktop.
# Tick Linux image for Ubuntu with all the necessary dependencies and
# environment variables. This Dockerfile can be used to test assertions that
# Tick was installed properly on Linux Ubuntu 18.04 and that it runs without
# needing to run `diesel_cli` commands to run the initial migraitons. This
# example is the first step to shipping a single binary for Tick cross-platform.
#
# Because of the life cycle of Docker containers, this container can only be
# used to run Tick commands in an ephemeral matter. Starting timers will only
# create timers which get destroyed when the tick command exits and the
# container is destroyed.
FROM ubuntu:18.04
# Prepare the directories that are going to be used.
RUN mkdir -p /src
RUN mkdir -p /db
# Prepare the environment variables for Rust and Tick.
ENV TICK_DATABASE_FILE=/db/docker-test.db
ENV PATH=/root/.cargo/bin:$PATH
# Update all the necessary dependencies for Rust and Tick.
RUN apt-get update && apt-get install -y \
curl \
sqlite3 \
build-essential \
libsqlite3-dev
# Install Rust using Rustup.
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
# Copy the freshly cloned Tick repository to the container.
COPY ./tick/ /src/tick
# Setup the .env file for Tick compilation.
RUN echo "TICK_DATABASE_FILE=/db/docker-test.db" > /src/tick/.env
# Build Tick with Cargo
RUN cd /src/tick && ~/.cargo/bin/cargo clean && ~/.cargo/bin/cargo build --release
# Install the Tick binary in the executable path.
RUN mv /src/tick/target/release/tick /usr/local/bin/tick
# Set the entry point to the binary so that `docker build -i tick-test "help"`
# is equivalent to running `tick help`.
ENTRYPOINT [ "tick" ]
@rogeruiz
Copy link
Author

rogeruiz commented Jun 3, 2021

# Create a directory for testing within the docker image.
>_ mkdir -p tick-test && cd "$_"
>_ git clone --branch add-testing https://github.com/rogeruiz/tick
>_ curl -L -o Dockerfile "https://gist.github.com/rogeruiz/829516010b42962a2e4c5097b4f6caa1/raw/c84cdca2a363f0e2edd2de0276899284916e9fd7/Dockerfile"

# Build the docker image and create a shell into it.
>_ docker build -t tick-test .
>_ docker run -it --entrypoint=/bin/bash tick-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment