Skip to content

Commit

Permalink
build(docker): Refactor test-base Dockerfile to avoid long build times
Browse files Browse the repository at this point in the history
  • Loading branch information
elldritch committed Jun 21, 2018
1 parent 5cccf4e commit a0c22ff
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 53 deletions.
23 changes: 15 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,31 @@ $(PREFIX)/fossa: $(BIN)/fossa
mv $< $@

# Building various Docker images.
.PHONY: docker-base
docker-base: ./docker/base/Dockerfile
sudo docker build -t quay.io/fossa/fossa-cli-base -f ./docker/base/Dockerfile .

docker-test-base: docker-base ./docker/test-base/Dockerfile
sudo docker build -t quay.io/fossa/fossa-cli-test-base -f ./docker/test-base/Dockerfile .

.PHONY: docker
docker: docker-base ./docker/devel/Dockerfile
sudo docker build -t fossa-cli -f ./docker/devel/Dockerfile .
sudo docker tag fossa-cli quay.io/fossa/fossa-cli
docker: docker-base ./docker/cli/Dockerfile
sudo docker build -t quay.io/fossa/fossa-cli -f ./docker/cli/Dockerfile .

.PHONY: docker-test
docker-test: docker-base ./docker/test/Dockerfile
sudo docker build -t fossa-cli-test -f ./docker/test/Dockerfile .
sudo docker tag fossa-cli-test quay.io/fossa/fossa-cli-test
docker-test: docker-test-base ./docker/test/Dockerfile
sudo docker build -t quay.io/fossa/fossa-cli-test -f ./docker/test/Dockerfile .

# Useful build tasks.
.PHONY: test
test: docker-test
sudo docker run fossa-cli-test
sudo docker run quay.io/fossa/fossa-cli-test

.PHONY: dev
dev: docker-test-base
sudo docker run -it \
-v $$GOPATH/github.com/fossas/fossa-cli:/home/fossa/go/src/github.com/fossas/fossa-cli \
-v $$GOPATH/bin:/home/fossa/go/bin \
quay.io/fossa/fossa-cli-test-base /bin/bash

.PHONY: install
install: $(PREFIX)/fossa
Expand Down
16 changes: 11 additions & 5 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
FROM ubuntu:16.04
# This Dockerfile provides all build tools that FOSSA CLI invokes. It's useful
# for trying out FOSSA CLI on machines that may not have all the necessary
# build tools.
FROM ubuntu:18.04

# Workaround for add-apt-repository (see https://github.com/oerdnj/deb.sury.org/issues/56)
ENV LC_ALL=C.UTF-8 DEBIAN_FRONTEND=noninteractive

# Housekeeping + CircleCI requirements
RUN apt-get update && \
apt-get -y install \
apt-get install -y \
# Useful scripting utilities
sudo \
# Required by CircleCI
Expand Down Expand Up @@ -77,20 +80,23 @@ RUN wget https://nodejs.org/dist/v8.9.4/node-v8.9.4-linux-x64.tar.xz -O /tmp/nod
npm config set prefix $HOME/.npm
ENV PATH=$PATH:/home/fossa/.npm/bin

# Install Node.js build tools
RUN npm i -g bower yarn
# Install Node.js build + debugging tools
RUN npm i -g bower yarn json

# Install Ruby runtime
RUN sudo apt-get install -y ruby-full

# Install Ruby build tools
RUN sudo gem install bundler

# Install Python runtime
RUN sudo apt-get install -y python

# Install Cocoapods
RUN sudo gem install cocoapods -v 0.39.0

# Install PHP runtime
RUN sudo apt-get install -y php7.2 php7.2-gd php7.2-curl php7.2-intl
RUN sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.2 php7.2-gd php7.2-curl php7.2-intl

# Install PHP build tools
RUN curl https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer && \
Expand Down
1 change: 1 addition & 0 deletions docker/devel/Dockerfile → docker/cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This Dockerfile contains the base tools and the pre-compiled FOSSA CLI.
FROM quay.io/fossa/fossa-cli-base

# Add FOSSA CLI
Expand Down
65 changes: 65 additions & 0 deletions docker/test-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This Dockerfile contains all the test fixtures for integration testing.
FROM quay.io/fossa/fossa-cli-base

# Known good Go projects (some are `git clone`d because `go get` causes
# compilation errors):
## Kubernetes (godep)
RUN mkdir -p $GOPATH/src/k8s.io && \
cd $GOPATH/src/k8s.io && \
git clone --depth=1 https://github.com/kubernetes/kubernetes && \
cd kubernetes && \
make ./cmd/kube-apiserver

## Consul (nested govendor)
RUN go get -u -v github.com/hashicorp/consul

## Docker, Docker CE (vndr)
RUN mkdir -p $GOPATH/src/github.com/docker && \
cd $GOPATH/src/github.com/docker && \
git clone --depth=1 https://github.com/docker/docker && \
git clone --depth=1 https://github.com/docker/docker-ce

## InfluxDB (gdm)
## This is an older version of InfluxDB that still used GDM -- the current
## revision has migrated to Dep.
RUN mkdir -p $GOPATH/src/github.com/influxdata && \
cd $GOPATH/src/github.com/influxdata && \
git clone https://github.com/influxdata/influxdb && \
cd influxdb && \
git reset --hard d606fcf19a5bb81566aac58cd223638a8720be2c && \
go get github.com/influxdata/influxdb/...

## rkt (glide)
RUN go get -u -v github.com/rkt/rkt/rkt

# Known good NodeJS projects
RUN git clone --depth=1 https://github.com/GoogleChrome/puppeteer && \
cd puppeteer && \
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 npm install --production
RUN git clone --depth=1 https://github.com/zeit/pkg && \
cd pkg && \
npm install --production
RUN git clone --depth=1 https://github.com/Marak/faker.js && \
cd faker.js && \
npm install --production
RUN git clone --depth=1 https://github.com/fastify/fastify && \
cd fastify && \
npm install --production
RUN git clone --depth=1 https://github.com/nestjs/nest && \
cd nest && \
npm install --production
RUN git clone --depth=1 https://github.com/harc/ohm && \
cd ohm && \
npm install --production
RUN git clone --depth=1 https://github.com/expressjs/express && \
cd express && \
npm install --production
RUN git clone --depth=1 https://github.com/standard/standard && \
cd standard && \
npm install --production
RUN git clone --depth=1 https://github.com/mafintosh/sodium-encryption && \
cd sodium-encryption && \
npm install --production
RUN git clone --depth=1 https://github.com/request/request && \
cd request && \
npm install --production
43 changes: 3 additions & 40 deletions docker/test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,5 @@
# We use fossa-cli-base instead of fossa-cli-devel because fossa-cli-devel has
# an ADD step, which invalidates the cache for all following steps. This causes
# a rebuild of Kubernetes, which takes _forever_.
FROM quay.io/fossa/fossa-cli-base

# Known good Go projects (some are `git clone`d because `go get` causes
# compilation errors):
## Kubernetes (godep)
RUN mkdir -p $GOPATH/src/k8s.io && \
cd $GOPATH/src/k8s.io && \
git clone --depth=1 https://github.com/kubernetes/kubernetes && \
cd kubernetes && \
make ./cmd/kube-apiserver

## Consul (nested govendor)
### This is currently vendored because of the go-discover vendor.json syntax
### error (see hashicorp/go-discover@266744f)
RUN mkdir -p $GOPATH/src/github.com/hashicorp && \
cd $GOPATH/src/github.com/hashicorp && \
git clone --depth=1 https://github.com/fossas/consul

## Docker, Docker CE (vndr)
RUN mkdir -p $GOPATH/src/github.com/docker && \
cd $GOPATH/src/github.com/docker && \
git clone --depth=1 https://github.com/docker/docker && \
git clone --depth=1 https://github.com/docker/docker-ce

## InfluxDB (gdm)
## This is an older version of InfluxDB that still used GDM -- the current
## revision has migrated to Dep.
RUN mkdir -p $GOPATH/src/github.com/influxdata && \
cd $GOPATH/src/github.com/influxdata && \
git clone https://github.com/influxdata/influxdb && \
cd influxdb && \
git reset --hard d606fcf19a5bb81566aac58cd223638a8720be2c && \
go get github.com/influxdata/influxdb/cmd/influx

## rkt (glide)
RUN go get -u -v github.com/rkt/rkt/rkt
# This Dockerfile contains the base tools and the pre-compiled FOSSA CLI.
FROM quay.io/fossa/fossa-cli-test-base

# Add FOSSA CLI
ADD . $GOPATH/src/github.com/fossas/fossa-cli
Expand All @@ -45,4 +8,4 @@ RUN sudo chown -R fossa:fossa $GOPATH/src/github.com/fossas && \
make

WORKDIR $GOPATH/src/github.com/fossas/fossa-cli
CMD [ "/bin/bash", "./test.sh" ]
CMD [ "/bin/bash", "./test.sh" ]

0 comments on commit a0c22ff

Please sign in to comment.