Skip to content

Commit

Permalink
Merge pull request #24 from jaustinpage/use_docker_tainer
Browse files Browse the repository at this point in the history
Use docker tainer
  • Loading branch information
jaustinpage authored Apr 19, 2017
2 parents 401a622 + b2780d0 commit 2b95071
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 46 deletions.
26 changes: 9 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,26 @@ version: 2
jobs:
build:
docker:
- image: ubuntu:latest
- image: jaustinpage/frc_rekt

working_directory: ~/frc_rekt
working_directory: /app/frc_rekt
steps:
- run:
command: |
apt-get update
apt-get install -y ca-certificates
- checkout

- restore-cache:
key: v2-requirements.txt-{{ checksum "requirements.txt" }}

- restore-cache:
key: v2-download_curves.py-{{ checksum "data/vex/download_curves.py" }}

- run:
command: |
scripts/dependencies
command: scripts/dependencies

- run:
command: scripts/test
command: scripts/py-dependencies

- save-cache:
key: v2-requirements.txt-{{ checksum "requirements.txt" }}
paths:
- ./env
- run:
command: scripts/download_curves

- run:
command: scripts/test

- save-cache:
key: v2-download_curves.py-{{ checksum "data/vex/download_curves.py" }}
Expand Down
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
*
# Add in requirements (! = not)
!requirements.txt
# Add back scripts
!scripts/*
# Add back data
!data/*
44 changes: 30 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
#
# frc_rekt dockerfile
# gets dependencies installed for fast builds
# Gets dependencies installed and cached for fast building.
# Intended to be used for cicd, not general purpose.
#
# https://github.com/jaustinpage/frc_rekt
#

FROM ubuntu

RUN \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y ca-certificates && \
apt-get install -y python3 && \
apt-get install -y python3-venv python3-pip libenchant1c2a && \
rm -rf /var/lib/apt/lists/*
# Get our dependencies file
COPY scripts/dependencies /tmp/dependencies

ADD requirements.txt /tmp/requirements.txt
# Run dependencies
RUN /tmp/dependencies

RUN \
python3 -m pip install --upgrade pip && \
python3 -m pip install -r /tmp/requirements.txt
WORKDIR /root/

ENV HOME /root
# Used to expire the layer if master has changed
ADD https://api.github.com/repos/jaustinpage/frc_rekt/compare/master...HEAD /dev/null
# We are cloning the git repo to speed up build time. NOTE: Must update from branch if testing code
RUN git clone https://github.com/jaustinpage/frc_rekt /app/frc_rekt

WORKDIR /root
# Switch working directory to git repo
WORKDIR /app/frc_rekt

# Note: Anything below this should be populating cached data, and should be "redone"
# at test time. The only reason for doing this ahead of time is to speed up building and testing
# A good rule: if it aint in .gitignore, you dont want it in the docker container
# Note 2: Don't rely on the github repo when running scripts, because when building in a branch,
# master file paths are not guarenteed. Instead, copy what you need.

# Download the python dependencies and populate our ./env virtualenv
COPY scripts/py-dependencies /tmp/py-dependencies
RUN /tmp/py-dependencies

# Copy the curves, to prevent excessive downloads from motors.vex.com
COPY data/vex data/vex/

# Download the curves, this should no-op, but just in case
COPY scripts/download_curves /tmp/download_curves
RUN /tmp/download_curves

CMD ["bash"]
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.PHONY: dependencies
dependencies:
scripts/dependencies
scripts/py-dependencies
scripts/download_curves

.PHONY: prep
prep:
Expand Down
35 changes: 20 additions & 15 deletions scripts/dependencies
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
#!/bin/bash
#!/bin/sh

set -e

# ubuntu dependencies
if [[ "$CIRCLECI" = "true" ]]; then
if [ $CIRCLECI == 'true' ]; then
echo "Packages needed are already installed, skipping."
elif systemd-detect-virt --container; then
echo "Installing packages on docker container."
apt-get update
apt-get install -y python3 python3-venv python3-pip libenchant1c2a
apt-get upgrade -y
apt-get install -y \
ca-certificates \
git \
libenchant1c2a \
python3 \
python3-pip \
python3-venv
rm -rf /var/lib/apt/lists/*
else
sudo apt-get install python3 python3-venv python3-pip libenchant1c2a
echo "Installing packages on your local ubuntu machine."
sudo apt-get install \
libenchant1c2a \
python3 \
python3-pip \
python3-venv
fi

python3 -m venv ./env

env/bin/python3 -m pip install --upgrade pip
env/bin/python3 -m pip install -r requirements.txt

echo "Remember to run source ./env/bin/activate now, and every time you start working"

# download curves
env/bin/python3 data/vex/download_curves.py
6 changes: 6 additions & 0 deletions scripts/download_curves
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

set -e

# download curves
env/bin/python3 data/vex/download_curves.py
10 changes: 10 additions & 0 deletions scripts/py-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

set -e

# create virtual environment
python3 -m venv ./env

# install requirements
env/bin/python3 -m pip install --upgrade pip
env/bin/python3 -m pip install -r requirements.txt

0 comments on commit 2b95071

Please sign in to comment.