Skip to content

Commit 13cd45c

Browse files
Minimize Docker images and automate relasing docker images (#31)
* Initial plan * Implement multi-stage Docker builds to minimize image size Co-authored-by: yutaro-sakamoto <[email protected]> * Add comprehensive size reduction summary documentation Co-authored-by: yutaro-sakamoto <[email protected]> * Remove OPTIMIZATION.md and SIZE_REDUCTION_SUMMARY.md documentation files Co-authored-by: yutaro-sakamoto <[email protected]> * fix: Dockerfile and utf8.Dockerfile * build: add build configuration files * fix: update docker-compose.yml * ci: run example programs in a Docker container * chore: rename Makefile to run.sh * fix: copying built files * fix: CLASSPATH defined in Dockerfile * ci: improve workflow triggers * ci: add experimental code that pushes docker images to DockerHub * fix: create an image with the tag `latest` * ci: deploy only when workflow_dispatch * ci: change settings to disable debug mode * build: change build-config.json to release new images * doc: update README.md * fix: apply copilot suggestions * chore: update Dockerfile * ci: add checks of versions of installed software --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]>
1 parent c0e1a56 commit 13cd45c

File tree

9 files changed

+235
-95
lines changed

9 files changed

+235
-95
lines changed

.github/workflows/ci.yml

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,91 @@
1-
name: test
1+
name: Build and Push Docker Image
22

33
on:
44
push:
55
pull_request:
6-
types: [opened, reopened, review_requested, synchronize]
6+
types: [opened, reopened, synchronize]
7+
workflow_dispatch:
8+
inputs:
9+
push_to_dockerhub:
10+
description: 'Push to Docker Hub'
11+
required: false
12+
default: 'false'
13+
type: boolean
714

815
jobs:
916
build:
1017
runs-on: ubuntu-latest
1118

1219
steps:
1320
- name: Checkout
14-
uses: actions/checkout@v4
21+
uses: actions/checkout@v5
22+
23+
- name: Load configuration
24+
run: |
25+
echo opensource_COBOL_4J_version="$(jq -r '.opensource_COBOL_4J_version' build-config.json)" >> $GITHUB_ENV
26+
echo Open_COBOL_ESQL_4J_version="$(jq -r '.Open_COBOL_ESQL_4J_version' build-config.json)" >> $GITHUB_ENV
27+
echo version_string_prefix="$(jq -r '.version_string_prefix' build-config.json)" >> $GITHUB_ENV
1528
1629
- name: Build a docker image
17-
run: docker build -t opensourcecobol/opensourcecobol4j .
30+
run: |
31+
docker build -t opensourcecobol/opensourcecobol4j:"$version_string_prefix" . \
32+
--build-arg opensource_COBOL_4J_version="$opensource_COBOL_4J_version" \
33+
--build-arg Open_COBOL_ESQL_4J_version="$Open_COBOL_ESQL_4J_version"
34+
35+
- name: Copy Docker image
36+
run: |
37+
docker tag opensourcecobol/opensourcecobol4j:"$version_string_prefix" opensourcecobol/opensourcecobol4j:latest
38+
39+
- name: Check the version of installed software
40+
run: |
41+
docker run --rm opensourcecobol/opensourcecobol4j:latest sh -c "cobj --version | grep 'opensource COBOL 4J $opensource_COBOL_4J_version'"
42+
docker run --rm opensourcecobol/opensourcecobol4j:latest sh -c "! cobj --version | grep 'unicode/utf-8 support'"
43+
docker run --rm opensourcecobol/opensourcecobol4j:latest sh -c "ocesql --version | grep 'Version $Open_COBOL_ESQL_4J_version'"
44+
45+
- name: Login to Docker Hub
46+
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.push_to_dockerhub == 'true'
47+
uses: docker/login-action@v3
48+
with:
49+
username: ${{ secrets.DOCKERHUB_USERNAME }}
50+
password: ${{ secrets.DOCKERHUB_TOKEN }}
51+
52+
- name: Push to Docker Hub
53+
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.push_to_dockerhub == 'true'
54+
run: |
55+
docker push opensourcecobol/opensourcecobol4j:"$version_string_prefix"
56+
docker push opensourcecobol/opensourcecobol4j:latest
1857
1958
utf8-build:
2059
runs-on: ubuntu-latest
2160

2261
steps:
2362
- name: Checkout
24-
uses: actions/checkout@v4
63+
uses: actions/checkout@v5
64+
65+
- name: Load configuration
66+
run: |
67+
echo opensource_COBOL_4J_version="$(jq -r '.opensource_COBOL_4J_version' build-config.json)" >> $GITHUB_ENV
68+
echo Open_COBOL_ESQL_4J_version="$(jq -r '.Open_COBOL_ESQL_4J_version' build-config.json)" >> $GITHUB_ENV
69+
echo version_string_prefix="$(jq -r '.version_string_prefix' build-config.json)" >> $GITHUB_ENV
2570
2671
- name: Build a docker image
27-
run: docker build -t opensourcecobol/opensourcecobol4j:utf8 . -f utf8.Dockerfile
72+
run: |
73+
docker build -t opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix" . -f utf8.Dockerfile \
74+
--build-arg opensource_COBOL_4J_version="$opensource_COBOL_4J_version"
75+
76+
- name: Check the version of installed software
77+
run: |
78+
docker run --rm opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix" sh -c "cobj --version | grep 'opensource COBOL 4J $opensource_COBOL_4J_version'"
79+
docker run --rm opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix" sh -c "cobj --version | grep 'unicode/utf-8 support'"
80+
81+
- name: Login to Docker Hub
82+
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.push_to_dockerhub == 'true'
83+
uses: docker/login-action@v3
84+
with:
85+
username: ${{ secrets.DOCKERHUB_USERNAME }}
86+
password: ${{ secrets.DOCKERHUB_TOKEN }}
87+
88+
- name: Push to Docker Hub
89+
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.push_to_dockerhub == 'true'
90+
run: |
91+
docker push opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix"

.github/workflows/docker-compose.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,24 @@ jobs:
1111

1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v5
15+
16+
- name: Load configuration
17+
run: |
18+
echo opensource_COBOL_4J_version="$(jq -r '.opensource_COBOL_4J_version' build-config.json)" >> $GITHUB_ENV
19+
echo Open_COBOL_ESQL_4J_version="$(jq -r '.Open_COBOL_ESQL_4J_version' build-config.json)" >> $GITHUB_ENV
20+
echo version_string_prefix="$(jq -r '.version_string_prefix' build-config.json)" >> $GITHUB_ENV
1521
1622
- name: Launch docker containers
17-
run: cd docker-compose && docker compose up -d
23+
working-directory: docker-compose
24+
run: |
25+
docker compose build \
26+
--build-arg opensource_COBOL_4J_version="$opensource_COBOL_4J_version" \
27+
--build-arg Open_COBOL_ESQL_4J_version="$Open_COBOL_ESQL_4J_version"
28+
docker compose up -d
29+
30+
- name: Run example programs
31+
working-directory: docker-compose
32+
run: |
33+
docker cp ../ocesql4j_sample oc4j_client:/tmp/ocesql4j_sample
34+
docker exec oc4j_client bash -c "cd /tmp/ocesql4j_sample && sh run.sh"

Dockerfile

Lines changed: 73 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,82 @@
1-
FROM almalinux:9
1+
# Build stage
2+
FROM almalinux:9 AS builder
23

3-
SHELL ["/bin/bash", "-c"]
4+
ARG opensource_COBOL_4J_version=dummy_value Open_COBOL_ESQL_4J_version=dummy_value
45

5-
# classpath settings
6-
ENV CLASSPATH=:/usr/lib/opensourcecobol4j/libcobj.jar:/usr/lib/Open-COBOL-ESQL-4j/postgresql.jar:/usr/lib/opensourcecobol4j/ocesql4j.jar
7-
RUN echo 'export CLASSPATH=:/usr/lib/opensourcecobol4j/libcobj.jar:/usr/lib/Open-COBOL-ESQL-4j/postgresql.jar:/usr/lib/Open-COBOL-ESQL-4j/ocesql4j.jar' >> ~/.bashrc
6+
SHELL ["/bin/bash", "-c"]
87

9-
# install dependencies
10-
RUN dnf update -y
11-
RUN dnf install -y gcc make bison flex automake autoconf diffutils gettext java-11-openjdk-devel
8+
# 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
1212

1313
# install sbt
14-
RUN curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz | gzip -d > cs && chmod +x cs && echo Y | ./cs setup
15-
16-
# install opensourcecobol4j
17-
RUN cd /root &&\
18-
curl -L -o opensourcecobol4j-v1.1.7.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v1.1.7.tar.gz &&\
19-
tar zxvf opensourcecobol4j-v1.1.7.tar.gz &&\
20-
cd opensourcecobol4j-1.1.7 &&\
21-
./configure --prefix=/usr/ &&\
22-
make &&\
23-
make install &&\
24-
rm /root/opensourcecobol4j-v1.1.7.tar.gz
25-
26-
# Install Open COBOL ESQL 4J
14+
RUN curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz | gzip -d > cs && \
15+
chmod +x cs && \
16+
echo Y | ./cs setup
17+
18+
# build opensourcecobol4j
19+
RUN cd /root && \
20+
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 && \
21+
tar zxvf opensourcecobol4j-v${opensource_COBOL_4J_version}.tar.gz && \
22+
cd opensourcecobol4j-${opensource_COBOL_4J_version} && \
23+
./configure --prefix=/usr/ && \
24+
make && \
25+
make install && \
26+
rm -rf /root/opensourcecobol4j-v${opensource_COBOL_4J_version}.tar.gz /root/opensourcecobol4j-${opensource_COBOL_4J_version}
27+
28+
# Download postgresql jar
29+
RUN mkdir -p /usr/lib/Open-COBOL-ESQL-4j/ && \
30+
curl -L -o /usr/lib/Open-COBOL-ESQL-4j/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.2.24.jar
31+
32+
# Build Open COBOL ESQL 4J
2733
ENV PATH="$PATH:/root/.local/share/coursier/bin"
28-
RUN mkdir -p /usr/lib/Open-COBOL-ESQL-4j &&\
29-
cd /root/ &&\
30-
curl -L -o Open-COBOL-ESQL-4j-1.1.1.tar.gz https://github.com/opensourcecobol/Open-COBOL-ESQL-4j/archive/refs/tags/v1.1.1.tar.gz &&\
31-
tar zxvf Open-COBOL-ESQL-4j-1.1.1.tar.gz &&\
32-
rm Open-COBOL-ESQL-4j-1.1.1.tar.gz &&\
33-
cd Open-COBOL-ESQL-4j-1.1.1 &&\
34-
mkdir -p /usr/lib/Open-COBOL-ESQL-4j/ &&\
35-
curl -L -o /usr/lib/Open-COBOL-ESQL-4j/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.2.24.jar &&\
36-
cp /usr/lib/opensourcecobol4j/libcobj.jar dblibj/lib &&\
37-
cp /usr/lib/Open-COBOL-ESQL-4j/postgresql.jar dblibj/lib &&\
38-
./configure --prefix=/usr/ &&\
39-
make &&\
40-
make install &&\
41-
rm -rf /root/Open-COBOL-ESQL-4j-1.1.1
34+
RUN cd /root/ && \
35+
curl -L -o Open-COBOL-ESQL-4j-${Open_COBOL_ESQL_4J_version}.tar.gz https://github.com/opensourcecobol/Open-COBOL-ESQL-4j/archive/refs/tags/v${Open_COBOL_ESQL_4J_version}.tar.gz && \
36+
tar zxvf Open-COBOL-ESQL-4j-${Open_COBOL_ESQL_4J_version}.tar.gz && \
37+
cd Open-COBOL-ESQL-4j-${Open_COBOL_ESQL_4J_version} && \
38+
cp /usr/lib/opensourcecobol4j/libcobj.jar dblibj/lib && \
39+
cp /usr/lib/Open-COBOL-ESQL-4j/postgresql.jar dblibj/lib && \
40+
./configure --prefix=/usr/ && \
41+
make && \
42+
make install && \
43+
rm -rf /root/Open-COBOL-ESQL-4j-${Open_COBOL_ESQL_4J_version}.tar.gz /root/Open-COBOL-ESQL-4j-${Open_COBOL_ESQL_4J_version}
44+
45+
# Runtime stage
46+
FROM almalinux:9
47+
48+
ARG opensource_COBOL_4J_version=dummy_value Open_COBOL_ESQL_4J_version=dummy_value
49+
50+
SHELL ["/bin/bash", "-c"]
51+
52+
# 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/*
57+
58+
# create required directories
59+
RUN mkdir -p /usr/lib/opensourcecobol4j \
60+
/usr/lib/Open-COBOL-ESQL-4j \
61+
/usr/bin/ \
62+
/usr/include/ \
63+
/usr/lib/share
64+
65+
# copy built files from builder stage
66+
COPY --from=builder /usr/lib/opensourcecobol4j/ /usr/lib/opensourcecobol4j/
67+
COPY --from=builder /usr/lib/Open-COBOL-ESQL-4j/ /usr/lib/Open-COBOL-ESQL-4j/
68+
COPY --from=builder /usr/bin/cob-config /usr/bin/cob-config
69+
COPY --from=builder /usr/bin/cobj /usr/bin/cobj
70+
COPY --from=builder /usr/bin/cobj-api /usr/bin/cobj-api
71+
COPY --from=builder /usr/bin/cobj-idx /usr/bin/cobj-idx
72+
COPY --from=builder /usr/bin/cobjrun /usr/bin/cobjrun
73+
COPY --from=builder /usr/bin/ocesql /usr/bin/ocesql
74+
COPY --from=builder /usr/include/libcobj.h /usr/include/libcobj.h
75+
COPY --from=builder /usr/share/opensource-cobol-4j-${opensource_COBOL_4J_version} /usr/share/opensource-cobol-4j-${opensource_COBOL_4J_version}
76+
77+
# classpath settings
78+
ENV CLASSPATH=:/usr/lib/opensourcecobol4j/libcobj.jar:/usr/lib/Open-COBOL-ESQL-4j/postgresql.jar:/usr/lib/Open-COBOL-ESQL-4j/ocesql4j.jar
79+
RUN echo 'export CLASSPATH=:/usr/lib/opensourcecobol4j/libcobj.jar:/usr/lib/Open-COBOL-ESQL-4j/postgresql.jar:/usr/lib/Open-COBOL-ESQL-4j/ocesql4j.jar' >> ~/.bashrc
4280

4381
# add sample programs
4482
ADD cobol_sample /root/cobol_sample

README.md

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
1-
# opensource COBOL 4J development environment (Docker)
1+
このリポジトリでは、GitHub Actionsを使用して、opensource COBOL 4J及びOpen COBOL ESQL 4JのインストールされたDockerイメージのリリースを行います。
22

3-
## Docker image
4-
Versions :
3+
# リリース手順
54

6-
- OS: Ubuntu
7-
- opensource COBOL 4J: v1.1.7
8-
- Open COBOL ESQL 4J: v1.1.1
5+
## build-config.jsonの編集
96

10-
In order to "Hello World" program, run the following commands in the docker container
7+
リリースするバージョンに合わせて、build-config.jsonを編集します。
8+
* opensource_COBOL_4J_version: Dockerイメージにインストールするopensource COBOL 4Jのバージョン
9+
* Open_COBOL_ESQL_4J_version: DockerイメージにインストールするOpen COBOL ESQL 4Jのバージョン
10+
* version_string_prefix: リリースするDockerイメージタグのプレフィックス
11+
* 例えば20250929を指定すると、以下の3つのタグを持つDockerイメージがビルドされ、Docker Hubにプッシュされます。
12+
* opensourcecobol/opensourcecobol4j:20250929
13+
* opensourcecobol/opensourcecobol4j:20250929-utf8
14+
* opensourcecobol/opensourcecobol4j:latest
1115

12-
```
13-
cd /root/cobol_sample
14-
cobj HELLO.cbl
15-
java HELLO
16-
```
16+
## ワークフローの手動実行
1717

18-
## Docker containers
18+
[公式ドキュメント](https://docs.github.com/ja/actions/how-tos/manage-workflow-runs/manually-run-a-workflow)を参考にして、ワークフローを手動で実行します。
1919

20-
In order to launch the environment with a database server and a client with opensource COBOL 4J Open COBOL ESQL 4J installed, run the following command.
20+
* ワークフロー名: `Build and Push Docker Image`
21+
* ブランチ: `main`
22+
* 入力パラメータ: `push_to_dockerhub``true`を指定
2123

22-
```bash
23-
cd docker-compose
24-
docker compose up -d
25-
docker attach oc4j_client
26-
```
24+
これによりDockerイメージがビルドされ、Docker HubにDockerイメージがプッシュされます。
2725

28-
Run the following in the docker container and execute sample programs of Open COBOL ESQL 4J.
29-
30-
```bash
31-
cd /root/ocesql4j_sample
32-
make
33-
```
34-
35-
Copyright 2021-2024, Tokyo System House Co., Ltd. <[email protected]>
26+
Copyright 2021-2025, Tokyo System House Co., Ltd. <[email protected]>

build-config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"opensource_COBOL_4J_version": "1.1.13",
3+
"Open_COBOL_ESQL_4J_version": "1.1.2",
4+
"version_string_prefix": "20250929"
5+
}

docker-compose/docker-compose.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ services:
1212
- "5432:5432"
1313

1414
oc4j_client:
15-
image: opensourcecobol/opensourcecobol4j:20241227
15+
build:
16+
context: ..
17+
dockerfile: Dockerfile
18+
args:
19+
- opensource_COBOL_4J_version=dummy_value
20+
- Open_COBOL_ESQL_4J_version=dummy_value
1621
container_name: oc4j_client
1722
stdin_open: true
1823
tty: true

ocesql4j_sample/Makefile

Lines changed: 0 additions & 6 deletions
This file was deleted.

ocesql4j_sample/run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ocesql INSERTTBL.cbl INSERTTBL.cob
2+
ocesql FETCHTBL.cbl FETCHTBL.cob
3+
cobj *.cob
4+
java INSERTTBL
5+
java FETCHTBL

0 commit comments

Comments
 (0)