Search code examples
pythondockertox

Copy and install packages within tox and set environment variables like you would in a Dockerfile


In my Dockerfile I have this:

ENV WORKDIR /home
ENV PYTHONPATH $WORKDIR
WORKDIR $WORKDIR

COPY resources/ $WORKDIR

# Install the JAVA
RUN tar -xvzf jdk-8u202-linux-x64.tar.gz -C /usr/
RUN rm jdk-8u202-linux-x64.tar.gz
ENV JAVA_HOME ../usr/jdk1.8.0_202
RUN export JAVA_HOME

Can I do the same in tox? I know you can run commands by specifying in tox.ini as follows:

[toxenv:test]
install_command = pip install {opts} {packages}
commands = 
    <command1>
    <command2>

But I just don't know if all the commands that would work in a Dockerfile would work in tox as well.


Solution

  • So I've tried it and it worked. To try implement the above, this is what I put in my tox.ini file:

    [testenv]
    
    setenv =
        LC_ALL = en_US.utf-8
        LANG = en_US.utf-8
        JAVA_HOME = {toxinidir}{/}jdk1.8.0_202
    allowlist_externals =
        tar
    commands =
        tar -xvzf resources/jdk-8u202-linux-x64.tar.gz
    

    allowlist_externals must be defined if you are gonna have commands like tar, cp, echo, ls etc.