clearlinux / distribution

Placeholder repository to allow filing of general bugs/issues/etc against the Clear Linux OS for Intel Architecture linux distribution
521 stars 29 forks source link

Cannot be set a certain clearlinux version on dockerfiles #977

Open lsandov1 opened 5 years ago

lsandov1 commented 5 years ago
  1. clone clearlinux/dockerfiles repository

  2. construct any multi-stage image ( for example cgit) with a desired CLR version

docker build --no-cache=true -t clearlinux/cgit --build-arg="-m 30170" dockerfiles/cgit/

  1. Check container's version
docker run -it clearlinux/cgit cat /usr/lib/os-release
NAME="Clear Linux OS"
VERSION=1
ID=clear-linux-os
ID_LIKE=clear-linux-os
VERSION_ID=30140
PRETTY_NAME="Clear Linux OS"
ANSI_COLOR="1;35"
HOME_URL="https://clearlinux.org"
SUPPORT_URL="https://clearlinux.org"
BUG_REPORT_URL="mailto:dev@lists.clearlinux.org"
PRIVACY_POLICY_URL="http://www.intel.com/privacy"

Desired result: container version should be the same as the one specified in the docker build parameter.

Current result: versions differ. In this case, 30170 != 30140. Seems that the one defining the version is clearlinux/os-core:latest

liujianjunhq commented 5 years ago

Yes, the container version is following clearlinux/os-core:latest when multi-stage build. To construct any multi-stage image with a desired CLR version, we could rebuild clearlinux/os-core with desired CLR version first. docker build --no-cache=true -t clearlinux/os-core:latest --build-arg swupd_args="-m 30170" os-core/ Then rebuild the dockerfile (for cgit, we need to rebuild clearlinux/httpd, then clearlinux/cgit): docker build --no-cache=true -t clearlinux/httpd:latest --build-arg httpd/ docker build --no-cache=true -t clearlinux/cgit:latest --build-arg cgit/ Please share if this way works for you. Thanks a lot for your finding!

qzheng527 commented 5 years ago

Or if you don't care much about the container image size (mutli-build way with os-core may save up to 150 MB), you can use the below traditional way.

" FROM clearlinux/httpd

ARG swupd_args RUN swupd update --no-boot-update $swupd_args RUN swupd bundle-add sudo curl scm-server $swupd_args \ && rm -rf /var/lib/swupd/*

COPY cgitrc /etc/cgitrc COPY httpd-cgit.conf /etc/httpd/conf.d/httpd-cgit.conf "

lsandov1 commented 5 years ago

@liujianjunhq thanks for sharing the workaround, although I have not tested. So we either document it (what you mentioned) or fix the dockerfile somehow. This can be an approach

@@ -5,13 +5,9 @@ FROM clearlinux:latest AS builder
 # correct
 RUN swupd update --no-boot-update $swupd_args

-# Grab os-release info from the minimal base image so
-# that the new content matches the exact OS version
-COPY --from=clearlinux/os-core:latest /usr/lib/os-release /
-
 # Install additional content in a target directory
 # using the os version from the minimal base
-RUN source /os-release && \
+RUN source /usr/lib/os-release && \
     mkdir /install_root \
     && swupd os-install -V ${VERSION_ID} \
     --path /install_root --statedir /swupd-state \

however, I have not tested it yet.

lsandov1 commented 5 years ago

@qzheng527 right. We do care about the space. We are using bundles with heavy packages so footprint is important. BTW, I did some analysis on the saved spaced, and the savings is around 10% compared to the non-multi-stage approach, so the multi-stage is indeed a good strategy (in terms of space and modularity..)

liujianjunhq commented 5 years ago

@lsandov1 thanks a lot for your sharing. Will document it and update the github. The reason to use "COPY --from=clearlinux/os-core:latest /usr/lib/os-release /" and "RUN source /os-release" is to keep the up layer image to have the same version as clearlinux/os-core, the base layer. Also, with the same clearlinux/os-core as base layer, we could share it among difference clearlinux containers to save further disk size. So, we need to keep the current approach. Thanks!

ephut commented 5 years ago

@bryteise