Skip to content

Commit

Permalink
feat(Generator): don't install Stencila language packages by default
Browse files Browse the repository at this point in the history
Currently, the Stencila R package is very slow to install so this turns that off
by default until that is sped up. Partially addresses #40 (still need to add argument on CLI)
  • Loading branch information
nokome committed Nov 6, 2018
1 parent 7569f8a commit 0dbd429
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 42 deletions.
5 changes: 3 additions & 2 deletions src/DockerCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export default class DockerCompiler {
* @param source The folder, Dockerfile or `SoftwareEnvironment` to compile
* @param build Should the Docker image be built?
* @param comments Should comments be added to the Dockerfile?
* @param stencila Should relevant Stencila language packages be installed in the image?
*/
async compile (source: string, build: boolean = true, comments: boolean = true): Promise<SoftwareEnvironment | null> {
async compile (source: string, build: boolean = true, comments: boolean = true, stencila: boolean = false): Promise<SoftwareEnvironment | null> {
let folder
if (source.substring(0, 7) === 'file://') {
folder = source.substring(7)
Expand Down Expand Up @@ -57,7 +58,7 @@ export default class DockerCompiler {

// Generate Dockerfile
dockerfile = '.Dockerfile'
new DockerGenerator(environ, folder).generate(comments)
new DockerGenerator(environ, folder).generate(comments, stencila)
}

if (build) {
Expand Down
13 changes: 8 additions & 5 deletions src/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export default class Generator extends Doer {
* Generate a Dockerfile for a `SoftwareEnvironment` instance
*
* @param comments Should a comments be added to the Dockerfile?
* @param stencila Should relevant Stencila language packages be installed in the image?
*/
generate (comments: boolean = true): string {
generate (comments: boolean = true, stencila: boolean = false): string {
let dockerfile = ''

if (comments) {
Expand Down Expand Up @@ -74,10 +75,12 @@ RUN apt-get update \\
`
}

let stencilaInstall = this.stencilaInstall(baseIdentifier)
if (stencilaInstall) {
if (comments) dockerfile += '\n# This section runs commands to install Stencila execution hosts.'
dockerfile += `\nRUN ${stencilaInstall}\n`
if (stencila) {
let stencilaInstall = this.stencilaInstall(baseIdentifier)
if (stencilaInstall) {
if (comments) dockerfile += '\n# This section runs commands to install Stencila execution hosts.'
dockerfile += `\nRUN ${stencilaInstall}\n`
}
}

// Once everything that needs root permissions is installed, switch the user to non-root for installing the rest of the packages.
Expand Down
2 changes: 1 addition & 1 deletion tests/DockerCompiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('compile:multi-lang', async () => {
let environ = await compiler.compile('file://' + fixture('multi-lang'), false, false)

// Remove the date from the MRAN line to allow for changing date of test v expected
const aptAddMRAN = /(apt-add-repository "deb https:\/\/mran.microsoft.com\/snapshot)\/([\d-]+)\/(bin\/linux\/ubuntu xenial\/)"/
const aptAddMRAN = /(apt-add-repository "deb https:\/\/mran.microsoft.com\/snapshot)\/([\d-]+)\/(bin\/linux\/ubuntu bionic-cran35\/)"/
const actual = fs.readFileSync(fixture('multi-lang/.Dockerfile'), 'utf8').replace(aptAddMRAN, '$1/YYYY-MM-DD/$3')
const expected = fs.readFileSync(fixture('multi-lang/Dockerfile.expected'), 'utf8').replace(aptAddMRAN, '$1/YYYY-MM-DD/$3')
expect(actual).toEqual(expected)
Expand Down
2 changes: 0 additions & 2 deletions tests/PythonGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ RUN apt-get update \\
&& apt-get clean \\
&& rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir https://github.com/stencila/py/archive/91a05a139ac120a89fc001d9d267989f062ad374.zip
RUN useradd --create-home --uid 1001 -s /bin/bash dockteruser
USER dockteruser
WORKDIR /home/dockteruser
Expand Down
20 changes: 0 additions & 20 deletions tests/RGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ RUN apt-get update \\
&& apt-get clean \\
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update \\
&& apt-get install -y zlib1g-dev libxml2-dev pkg-config \\
&& apt-get autoremove -y \\
&& apt-get clean \\
&& rm -rf /var/lib/apt/lists/* \\
&& Rscript -e 'install.packages("devtools")' \\
&& Rscript -e 'source("https://bioconductor.org/biocLite.R"); biocLite("graph")' \\
&& Rscript -e 'devtools::install_github("r-lib/pkgbuild")' \\
&& Rscript -e 'devtools::install_github("stencila/r")'
RUN useradd --create-home --uid 1001 -s /bin/bash dockteruser
USER dockteruser
WORKDIR /home/dockteruser
Expand Down Expand Up @@ -104,16 +94,6 @@ RUN apt-get update \\
&& apt-get clean \\
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update \\
&& apt-get install -y zlib1g-dev libxml2-dev pkg-config \\
&& apt-get autoremove -y \\
&& apt-get clean \\
&& rm -rf /var/lib/apt/lists/* \\
&& Rscript -e 'install.packages("devtools")' \\
&& Rscript -e 'source("https://bioconductor.org/biocLite.R"); biocLite("graph")' \\
&& Rscript -e 'devtools::install_github("r-lib/pkgbuild")' \\
&& Rscript -e 'devtools::install_github("stencila/r")'
RUN useradd --create-home --uid 1001 -s /bin/bash dockteruser
USER dockteruser
WORKDIR /home/dockteruser
Expand Down
12 changes: 0 additions & 12 deletions tests/fixtures/multi-lang/Dockerfile.expected
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ RUN apt-get update \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN npm install [email protected] \
&& pip3 install --no-cache-dir https://github.com/stencila/py/archive/91a05a139ac120a89fc001d9d267989f062ad374.zip \
&& apt-get update \
&& apt-get install -y zlib1g-dev libxml2-dev pkg-config \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& Rscript -e 'install.packages("devtools")' \
&& Rscript -e 'source("https://bioconductor.org/biocLite.R"); biocLite("graph")' \
&& Rscript -e 'devtools::install_github("r-lib/pkgbuild")' \
&& Rscript -e 'devtools::install_github("stencila/r")'

RUN useradd --create-home --uid 1001 -s /bin/bash dockteruser
USER dockteruser
WORKDIR /home/dockteruser
Expand Down

0 comments on commit 0dbd429

Please sign in to comment.