Skip to content

Commit 98bc2fa

Browse files
authored
Merge pull request #2 from quay/dockerfile-refactor
dockerfile: refactor build
2 parents 45c1cb9 + d33bda2 commit 98bc2fa

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

Dockerfile

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
1-
FROM centos:8 as executor-img
1+
FROM centos:8 as base
2+
ARG channel="stable"
23
ARG location
3-
ARG channel
4-
ARG version
54

6-
RUN [ -z "${location}" ] || [ -z "${channel}" ] || [ -z "${version}" ] && echo "ARG location, channel, version are required" && exit 1 || true
5+
RUN [ -z "${channel}" ] && echo "ARG channel is required" && exit 1 || true
76

8-
RUN echo "Downloading" ${location}
9-
RUN curl -s -o coreos_production_qemu_image.qcow2.xz ${location} && unxz coreos_production_qemu_image.qcow2.xz
7+
RUN yum -y install jq
8+
RUN curl https://builds.coreos.fedoraproject.org/streams/${channel}.json -o stable.json && \
9+
cat stable.json | jq '.architectures.x86_64.artifacts.qemu.release' | tr -d '"'
1010

1111

12-
FROM centos:8
13-
ARG location
14-
ARG channel
15-
ARG version
12+
FROM base AS executor-img
13+
14+
RUN if [[ -z "$arg" ]] ; then \
15+
echo "Downloading" $(cat stable.json | jq '.architectures.x86_64.artifacts.qemu.formats."qcow2.xz".disk.location' | tr -d '"') && \
16+
curl -s -o coreos_production_qemu_image.qcow2.xz $(cat stable.json | jq '.architectures.x86_64.artifacts.qemu.formats."qcow2.xz".disk.location' | tr -d '"') && unxz coreos_production_qemu_image.qcow2.xz ; \
17+
else \
18+
echo "Downloading" ${location} && \
19+
curl -s -o coreos_production_qemu_image.qcow2.xz ${location} && unxz coreos_production_qemu_image.qcow2.xz \
20+
; fi
21+
22+
23+
FROM base AS final
24+
ARG channel=stable
1625

1726
RUN mkdir -p /userdata
1827
WORKDIR /userdata
1928

2029
RUN yum -y update && \
21-
yum -y install openssh-clients qemu-kvm && \
22-
yum -y clean all
30+
yum -y remove jq && \
31+
yum -y install openssh-clients qemu-kvm && \
32+
yum -y clean all
2333

2434
COPY --from=executor-img /coreos_production_qemu_image.qcow2 /userdata/coreos_production_qemu_image.qcow2
2535
COPY start.sh /userdata/start.sh
@@ -28,6 +38,5 @@ RUN chgrp -R 0 /userdata && \
2838
chmod -R g=u /userdata
2939

3040
LABEL com.coreos.channel ${channel}
31-
LABEL com.coreos.version ${version}
3241

3342
ENTRYPOINT ["/bin/bash", "/userdata/start.sh"]

build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ CLOUD_IMAGE=${CLOUD_IMAGE:-""}
77

88
if [ -z "$CLOUD_IMAGE" ]; then
99
CHANNEL=${CHANNEL:-"stable"}
10-
CHANNEL_MANIFEST_JSON=`curl https://builds.coreos.fedoraproject.org/streams/stable.json`
10+
CHANNEL_MANIFEST_JSON=`curl https://builds.coreos.fedoraproject.org/streams/${CHANNEL}.json`
1111
LOCATION=`echo $CHANNEL_MANIFEST_JSON | jq '.architectures.x86_64.artifacts.qemu.formats."qcow2.xz".disk.location' | tr -d '"'`
1212
VERSION=`echo $CHANNEL_MANIFEST_JSON | jq '.architectures.x86_64.artifacts.qemu.release' | tr -d '"'`
1313

14-
time docker build --build-arg=channel=$CHANNEL --build-arg version=$VERSION --build-arg location=$LOCATION -t $IMAGE:$TAG .
14+
time docker build --build-arg=channel=$CHANNEL --build-arg --build-arg -t $IMAGE:$TAG .
1515
else
16-
time docker build --build-arg=channel=$CHANNEL --build-arg version=$VERSION --build-arg location=$CLOUD_IMAGE -t $IMAGE:$TAG .
16+
time docker build --build-arg=channel=$CHANNEL --build-arg --build-arg location=$CLOUD_IMAGE -t $IMAGE:$TAG .
1717
fi

0 commit comments

Comments
 (0)