Skip to content

Commit ae91ec7

Browse files
Optimize the size of docker images and fix utf8.Dockerfile (#36)
* build: change the base image to almalinux:9-minimal * ci: show the Docker image size * ci: run simple tests inside the container * ci: add COPY commands into utf8.Dockerfile * fix: add the definition of build arguments * ci: remove unnecessary COPY commands * fix: the value of the option `--prefix` * ci: change the order of verifications
1 parent 7706dd1 commit ae91ec7

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ jobs:
3636
run: |
3737
docker tag opensourcecobol/opensourcecobol4j:"$version_string_prefix" opensourcecobol/opensourcecobol4j:latest
3838
39+
- name: Show Docker image size
40+
run: |
41+
docker images opensourcecobol/opensourcecobol4j:"$version_string_prefix" --format "table {{.Repository}}:{{.Tag}}\t{{.Size}}"
42+
3943
- name: Check the version of installed software
4044
run: |
4145
docker run --rm opensourcecobol/opensourcecobol4j:latest sh -c "cobj --version | grep 'opensource COBOL 4J $opensource_COBOL_4J_version'"
4246
docker run --rm opensourcecobol/opensourcecobol4j:latest sh -c "! cobj --version | grep 'unicode/utf-8 support'"
4347
docker run --rm opensourcecobol/opensourcecobol4j:latest sh -c "ocesql --version | grep 'Version $Open_COBOL_ESQL_4J_version'"
4448
49+
- name: Run simple tests inside the container
50+
run: |
51+
docker run -itd --name test_container opensourcecobol/opensourcecobol4j:latest
52+
docker exec test_container sh -c "cd /root/cobol_sample && cobj HELLO.cbl && java HELLO"
53+
docker rm -f test_container
54+
4555
- name: Login to Docker Hub
4656
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.push_to_dockerhub == true
4757
uses: docker/login-action@v3
@@ -73,11 +83,21 @@ jobs:
7383
docker build -t opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix" . -f utf8.Dockerfile \
7484
--build-arg opensource_COBOL_4J_version="$opensource_COBOL_4J_version"
7585
86+
- name: Show Docker image size
87+
run: |
88+
docker images opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix" --format "table {{.Repository}}:{{.Tag}}\t{{.Size}}"
89+
7690
- name: Check the version of installed software
7791
run: |
7892
docker run --rm opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix" sh -c "cobj --version | grep 'opensource COBOL 4J $opensource_COBOL_4J_version'"
7993
docker run --rm opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix" sh -c "cobj --version | grep 'unicode/utf-8 support'"
8094
95+
- name: Run simple tests inside the container
96+
run: |
97+
docker run -itd --name test_container opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix"
98+
docker exec test_container sh -c "cd /root/cobol_sample && cobj HELLO.cbl && java HELLO"
99+
docker rm -f test_container
100+
81101
- name: Login to Docker Hub
82102
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.push_to_dockerhub == true
83103
uses: docker/login-action@v3

Dockerfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Build stage
2-
FROM almalinux:9 AS builder
2+
FROM almalinux:9-minimal AS builder
33

44
ARG opensource_COBOL_4J_version=dummy_value Open_COBOL_ESQL_4J_version=dummy_value
55

66
SHELL ["/bin/bash", "-c"]
77

88
# install build dependencies
9-
RUN dnf update -y && \
10-
dnf install -y gcc make bison flex automake autoconf diffutils gettext java-11-openjdk-devel && \
11-
dnf clean all
9+
RUN microdnf update -y && \
10+
microdnf install -y gcc make bison flex automake autoconf diffutils gettext java-11-openjdk-devel tar gzip && \
11+
microdnf clean all
1212

1313
# install sbt
1414
RUN curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz | gzip -d > cs && \
@@ -43,17 +43,17 @@ RUN cd /root/ && \
4343
rm -rf /root/Open-COBOL-ESQL-4j-${Open_COBOL_ESQL_4J_version}.tar.gz /root/Open-COBOL-ESQL-4j-${Open_COBOL_ESQL_4J_version}
4444

4545
# Runtime stage
46-
FROM almalinux:9
46+
FROM almalinux:9-minimal
4747

4848
ARG opensource_COBOL_4J_version=dummy_value Open_COBOL_ESQL_4J_version=dummy_value
4949

5050
SHELL ["/bin/bash", "-c"]
5151

5252
# install runtime dependencies only
53-
RUN dnf update -y && \
54-
dnf install -y java-11-openjdk-devel && \
55-
dnf clean all && \
56-
rm -rf /var/cache/dnf/*
53+
RUN microdnf update -y && \
54+
microdnf install -y java-11-openjdk-devel && \
55+
microdnf clean all && \
56+
rm -rf /var/cache/microdnf/*
5757

5858
# create required directories
5959
RUN mkdir -p /usr/lib/opensourcecobol4j \

utf8.Dockerfile

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Build stage
2-
FROM almalinux:9 AS builder
2+
FROM almalinux:9-minimal AS builder
33

44
ARG opensource_COBOL_4J_version=dummy_value
55

66
SHELL ["/bin/bash", "-c"]
77

88
# install build dependencies
9-
RUN dnf update -y && \
10-
dnf install -y gcc make bison flex automake autoconf diffutils gettext java-11-openjdk-devel && \
11-
dnf clean all
9+
RUN microdnf update -y && \
10+
microdnf install -y gcc make bison flex automake autoconf diffutils gettext java-11-openjdk-devel tar gzip && \
11+
microdnf clean all
1212

1313
# install sbt
1414
RUN curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz | gzip -d > cs && \
@@ -20,26 +20,34 @@ RUN cd /root && \
2020
curl -L -o opensourcecobol4j-v${opensource_COBOL_4J_version}.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v${opensource_COBOL_4J_version}.tar.gz && \
2121
tar zxvf opensourcecobol4j-v${opensource_COBOL_4J_version}.tar.gz && \
2222
cd opensourcecobol4j-${opensource_COBOL_4J_version} && \
23-
mkdir -p /tmp/usr/ &&\
24-
./configure --prefix=/tmp/usr/ --enable-utf8 && \
23+
./configure --prefix=/usr/ --enable-utf8 && \
2524
touch cobj/*.m4 && \
2625
make && \
2726
make install && \
2827
rm -rf /root/opensourcecobol4j-v${opensource_COBOL_4J_version}.tar.gz /root/opensourcecobol4j-${opensource_COBOL_4J_version}
2928

3029
# Runtime stage
31-
FROM almalinux:9
30+
FROM almalinux:9-minimal
31+
32+
ARG opensource_COBOL_4J_version=dummy_value
3233

3334
SHELL ["/bin/bash", "-c"]
3435

3536
# install runtime dependencies only
36-
RUN dnf update -y && \
37-
dnf install -y java-11-openjdk-devel && \
38-
dnf clean all && \
39-
rm -rf /var/cache/dnf/*
37+
RUN microdnf update -y && \
38+
microdnf install -y java-11-openjdk-devel && \
39+
microdnf clean all && \
40+
rm -rf /var/cache/microdnf/*
4041

4142
# copy built files from builder stage
42-
COPY --from=builder /tmp/usr/ /usr/
43+
COPY --from=builder /usr/lib/opensourcecobol4j/ /usr/lib/opensourcecobol4j/
44+
COPY --from=builder /usr/bin/cob-config /usr/bin/cob-config
45+
COPY --from=builder /usr/bin/cobj /usr/bin/cobj
46+
COPY --from=builder /usr/bin/cobj-api /usr/bin/cobj-api
47+
COPY --from=builder /usr/bin/cobj-idx /usr/bin/cobj-idx
48+
COPY --from=builder /usr/bin/cobjrun /usr/bin/cobjrun
49+
COPY --from=builder /usr/include/libcobj.h /usr/include/libcobj.h
50+
COPY --from=builder /usr/share/opensource-cobol-4j-${opensource_COBOL_4J_version} /usr/share/opensource-cobol-4j-${opensource_COBOL_4J_version}
4351

4452
# classpath settings
4553
ENV CLASSPATH=:/usr/lib/opensourcecobol4j/libcobj.jar

0 commit comments

Comments
 (0)