Skip to content

Commit 56b349d

Browse files
LucasRoesleralexellis
authored andcommitted
feat: use chown during copy to reduce image size and build time
Using the `--chown` flag during `COPY` is much faster than running `chown -R`. It also removes a layer from the image, resulting in faster and smaller builds. Resolves #55 Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
1 parent bf64898 commit 56b349d

File tree

6 files changed

+21
-25
lines changed

6 files changed

+21
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

template/python27-flask/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@ ENV PATH=$PATH:/home/app/.local/bin
1818

1919
WORKDIR /home/app/
2020

21-
COPY index.py .
22-
COPY requirements.txt .
21+
COPY --chown=app:app index.py .
22+
COPY --chown=app:app requirements.txt .
2323
USER root
2424
RUN pip install -r requirements.txt
2525
USER app
2626

2727
RUN mkdir -p function
2828
RUN touch ./function/__init__.py
2929
WORKDIR /home/app/function/
30-
COPY function/requirements.txt .
30+
COPY --chown=app:app function/requirements.txt .
3131
RUN pip install --user -r requirements.txt
3232

3333
WORKDIR /home/app/
3434

3535
USER root
36-
COPY function function
37-
RUN chown -R app:app ./
36+
COPY --chown=app:app function function
3837
USER app
3938

4039
ENV fprocess="python index.py"

template/python3-flask-debian/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ ENV PATH=$PATH:/home/app/.local/bin
1919

2020
WORKDIR /home/app/
2121

22-
COPY index.py .
23-
COPY requirements.txt .
22+
COPY --chown=app:app index.py .
23+
COPY --chown=app:app requirements.txt .
2424

2525
USER root
2626
RUN pip install -r requirements.txt
@@ -31,14 +31,13 @@ USER app
3131
RUN mkdir -p function
3232
RUN touch ./function/__init__.py
3333
WORKDIR /home/app/function/
34-
COPY function/requirements.txt .
34+
COPY --chown=app:app function/requirements.txt .
3535
RUN pip install --user -r requirements.txt
3636

3737
#install function code
3838
USER root
3939

40-
COPY function/ .
41-
RUN chown -R app:app ../
40+
COPY --chown=app:app function/ .
4241

4342
ARG TEST_COMMAND=tox
4443
ARG TEST_ENABLED=true

template/python3-flask/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ ENV PATH=$PATH:/home/app/.local/bin
1919

2020
WORKDIR /home/app/
2121

22-
COPY index.py .
23-
COPY requirements.txt .
22+
COPY --chown=app:app index.py .
23+
COPY --chown=app:app requirements.txt .
2424

2525
USER root
2626
RUN pip install -r requirements.txt
@@ -31,14 +31,13 @@ USER app
3131
RUN mkdir -p function
3232
RUN touch ./function/__init__.py
3333
WORKDIR /home/app/function/
34-
COPY function/requirements.txt .
34+
COPY --chown=app:app function/requirements.txt .
3535
RUN pip install --user -r requirements.txt
3636

3737
#install function code
3838
USER root
3939

40-
COPY function/ .
41-
RUN chown -R app:app ../
40+
COPY --chown=app:app function/ .
4241

4342
ARG TEST_COMMAND=tox
4443
ARG TEST_ENABLED=true

template/python3-http-debian/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,20 @@ ENV PATH=$PATH:/home/app/.local/bin
1919

2020
WORKDIR /home/app/
2121

22-
COPY index.py .
23-
COPY requirements.txt .
22+
COPY --chown=app:app index.py .
23+
COPY --chown=app:app requirements.txt .
2424
USER root
2525
RUN pip install -r requirements.txt
2626
USER app
2727

2828
RUN mkdir -p function
2929
RUN touch ./function/__init__.py
3030
WORKDIR /home/app/function/
31-
COPY function/requirements.txt .
31+
COPY --chown=app:app function/requirements.txt .
3232
RUN pip install --user -r requirements.txt
3333

3434
USER root
35-
COPY function/ .
36-
RUN chown -R app:app ../
35+
COPY --chown=app:app function/ .
3736

3837
ARG TEST_COMMAND=tox
3938
ARG TEST_ENABLED=true

template/python3-http/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ ENV PATH=$PATH:/home/app/.local/bin
1919

2020
WORKDIR /home/app/
2121

22-
COPY index.py .
23-
COPY requirements.txt .
22+
COPY --chown=app:app index.py .
23+
COPY --chown=app:app requirements.txt .
2424
USER root
2525
RUN pip install -r requirements.txt
2626

@@ -30,13 +30,12 @@ USER app
3030
RUN mkdir -p function
3131
RUN touch ./function/__init__.py
3232
WORKDIR /home/app/function/
33-
COPY function/requirements.txt .
33+
COPY --chown=app:app function/requirements.txt .
3434
RUN pip install --user -r requirements.txt
3535

3636
# install function code
3737
USER root
38-
COPY function/ .
39-
RUN chown -R app:app ../
38+
COPY --chown=app:app function/ .
4039

4140
ARG TEST_COMMAND=tox
4241
ARG TEST_ENABLED=true

0 commit comments

Comments
 (0)