diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e81e21..cf75522 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,16 @@ -name: test +name: Build and Push Docker Image on: push: pull_request: - types: [opened, reopened, review_requested, synchronize] + types: [opened, reopened, synchronize] + workflow_dispatch: + inputs: + push_to_dockerhub: + description: 'Push to Docker Hub' + required: false + default: 'false' + type: boolean jobs: build: @@ -11,17 +18,74 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v5 + + - name: Load configuration + run: | + echo opensource_COBOL_4J_version="$(jq -r '.opensource_COBOL_4J_version' build-config.json)" >> $GITHUB_ENV + echo Open_COBOL_ESQL_4J_version="$(jq -r '.Open_COBOL_ESQL_4J_version' build-config.json)" >> $GITHUB_ENV + echo version_string_prefix="$(jq -r '.version_string_prefix' build-config.json)" >> $GITHUB_ENV - name: Build a docker image - run: docker build -t opensourcecobol/opensourcecobol4j . + run: | + docker build -t opensourcecobol/opensourcecobol4j:"$version_string_prefix" . \ + --build-arg opensource_COBOL_4J_version="$opensource_COBOL_4J_version" \ + --build-arg Open_COBOL_ESQL_4J_version="$Open_COBOL_ESQL_4J_version" + + - name: Copy Docker image + run: | + docker tag opensourcecobol/opensourcecobol4j:"$version_string_prefix" opensourcecobol/opensourcecobol4j:latest + + - name: Check the version of installed software + run: | + docker run --rm opensourcecobol/opensourcecobol4j:latest sh -c "cobj --version | grep 'opensource COBOL 4J $opensource_COBOL_4J_version'" + docker run --rm opensourcecobol/opensourcecobol4j:latest sh -c "! cobj --version | grep 'unicode/utf-8 support'" + docker run --rm opensourcecobol/opensourcecobol4j:latest sh -c "ocesql --version | grep 'Version $Open_COBOL_ESQL_4J_version'" + + - name: Login to Docker Hub + if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.push_to_dockerhub == 'true' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Push to Docker Hub + if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.push_to_dockerhub == 'true' + run: | + docker push opensourcecobol/opensourcecobol4j:"$version_string_prefix" + docker push opensourcecobol/opensourcecobol4j:latest utf8-build: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v5 + + - name: Load configuration + run: | + echo opensource_COBOL_4J_version="$(jq -r '.opensource_COBOL_4J_version' build-config.json)" >> $GITHUB_ENV + echo Open_COBOL_ESQL_4J_version="$(jq -r '.Open_COBOL_ESQL_4J_version' build-config.json)" >> $GITHUB_ENV + echo version_string_prefix="$(jq -r '.version_string_prefix' build-config.json)" >> $GITHUB_ENV - name: Build a docker image - run: docker build -t opensourcecobol/opensourcecobol4j:utf8 . -f utf8.Dockerfile \ No newline at end of file + run: | + docker build -t opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix" . -f utf8.Dockerfile \ + --build-arg opensource_COBOL_4J_version="$opensource_COBOL_4J_version" + + - name: Check the version of installed software + run: | + docker run --rm opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix" sh -c "cobj --version | grep 'opensource COBOL 4J $opensource_COBOL_4J_version'" + docker run --rm opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix" sh -c "cobj --version | grep 'unicode/utf-8 support'" + + - name: Login to Docker Hub + if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.push_to_dockerhub == 'true' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Push to Docker Hub + if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.push_to_dockerhub == 'true' + run: | + docker push opensourcecobol/opensourcecobol4j:utf8-"$version_string_prefix" diff --git a/.github/workflows/docker-compose.yml b/.github/workflows/docker-compose.yml index b0622a7..da01271 100644 --- a/.github/workflows/docker-compose.yml +++ b/.github/workflows/docker-compose.yml @@ -11,7 +11,24 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v5 + + - name: Load configuration + run: | + echo opensource_COBOL_4J_version="$(jq -r '.opensource_COBOL_4J_version' build-config.json)" >> $GITHUB_ENV + echo Open_COBOL_ESQL_4J_version="$(jq -r '.Open_COBOL_ESQL_4J_version' build-config.json)" >> $GITHUB_ENV + echo version_string_prefix="$(jq -r '.version_string_prefix' build-config.json)" >> $GITHUB_ENV - name: Launch docker containers - run: cd docker-compose && docker compose up -d + working-directory: docker-compose + run: | + docker compose build \ + --build-arg opensource_COBOL_4J_version="$opensource_COBOL_4J_version" \ + --build-arg Open_COBOL_ESQL_4J_version="$Open_COBOL_ESQL_4J_version" + docker compose up -d + + - name: Run example programs + working-directory: docker-compose + run: | + docker cp ../ocesql4j_sample oc4j_client:/tmp/ocesql4j_sample + docker exec oc4j_client bash -c "cd /tmp/ocesql4j_sample && sh run.sh" diff --git a/Dockerfile b/Dockerfile index b164bb0..a2e3e48 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,44 +1,82 @@ -FROM almalinux:9 +# Build stage +FROM almalinux:9 AS builder -SHELL ["/bin/bash", "-c"] +ARG opensource_COBOL_4J_version=dummy_value Open_COBOL_ESQL_4J_version=dummy_value -# classpath settings -ENV CLASSPATH=:/usr/lib/opensourcecobol4j/libcobj.jar:/usr/lib/Open-COBOL-ESQL-4j/postgresql.jar:/usr/lib/opensourcecobol4j/ocesql4j.jar -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 +SHELL ["/bin/bash", "-c"] -# install dependencies -RUN dnf update -y -RUN dnf install -y gcc make bison flex automake autoconf diffutils gettext java-11-openjdk-devel +# install build dependencies +RUN dnf update -y && \ + dnf install -y gcc make bison flex automake autoconf diffutils gettext java-11-openjdk-devel && \ + dnf clean all # install sbt -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 - -# install opensourcecobol4j -RUN cd /root &&\ - curl -L -o opensourcecobol4j-v1.1.7.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v1.1.7.tar.gz &&\ - tar zxvf opensourcecobol4j-v1.1.7.tar.gz &&\ - cd opensourcecobol4j-1.1.7 &&\ - ./configure --prefix=/usr/ &&\ - make &&\ - make install &&\ - rm /root/opensourcecobol4j-v1.1.7.tar.gz - -# Install Open COBOL ESQL 4J +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 + +# build opensourcecobol4j +RUN cd /root && \ + 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 && \ + tar zxvf opensourcecobol4j-v${opensource_COBOL_4J_version}.tar.gz && \ + cd opensourcecobol4j-${opensource_COBOL_4J_version} && \ + ./configure --prefix=/usr/ && \ + make && \ + make install && \ + rm -rf /root/opensourcecobol4j-v${opensource_COBOL_4J_version}.tar.gz /root/opensourcecobol4j-${opensource_COBOL_4J_version} + +# Download postgresql jar +RUN mkdir -p /usr/lib/Open-COBOL-ESQL-4j/ && \ + curl -L -o /usr/lib/Open-COBOL-ESQL-4j/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.2.24.jar + +# Build Open COBOL ESQL 4J ENV PATH="$PATH:/root/.local/share/coursier/bin" -RUN mkdir -p /usr/lib/Open-COBOL-ESQL-4j &&\ - cd /root/ &&\ - 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 &&\ - tar zxvf Open-COBOL-ESQL-4j-1.1.1.tar.gz &&\ - rm Open-COBOL-ESQL-4j-1.1.1.tar.gz &&\ - cd Open-COBOL-ESQL-4j-1.1.1 &&\ - mkdir -p /usr/lib/Open-COBOL-ESQL-4j/ &&\ - curl -L -o /usr/lib/Open-COBOL-ESQL-4j/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.2.24.jar &&\ - cp /usr/lib/opensourcecobol4j/libcobj.jar dblibj/lib &&\ - cp /usr/lib/Open-COBOL-ESQL-4j/postgresql.jar dblibj/lib &&\ - ./configure --prefix=/usr/ &&\ - make &&\ - make install &&\ - rm -rf /root/Open-COBOL-ESQL-4j-1.1.1 +RUN cd /root/ && \ + 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 && \ + tar zxvf Open-COBOL-ESQL-4j-${Open_COBOL_ESQL_4J_version}.tar.gz && \ + cd Open-COBOL-ESQL-4j-${Open_COBOL_ESQL_4J_version} && \ + cp /usr/lib/opensourcecobol4j/libcobj.jar dblibj/lib && \ + cp /usr/lib/Open-COBOL-ESQL-4j/postgresql.jar dblibj/lib && \ + ./configure --prefix=/usr/ && \ + make && \ + make install && \ + rm -rf /root/Open-COBOL-ESQL-4j-${Open_COBOL_ESQL_4J_version}.tar.gz /root/Open-COBOL-ESQL-4j-${Open_COBOL_ESQL_4J_version} + +# Runtime stage +FROM almalinux:9 + +ARG opensource_COBOL_4J_version=dummy_value Open_COBOL_ESQL_4J_version=dummy_value + +SHELL ["/bin/bash", "-c"] + +# install runtime dependencies only +RUN dnf update -y && \ + dnf install -y java-11-openjdk-devel && \ + dnf clean all && \ + rm -rf /var/cache/dnf/* + +# create required directories +RUN mkdir -p /usr/lib/opensourcecobol4j \ + /usr/lib/Open-COBOL-ESQL-4j \ + /usr/bin/ \ + /usr/include/ \ + /usr/lib/share + +# copy built files from builder stage +COPY --from=builder /usr/lib/opensourcecobol4j/ /usr/lib/opensourcecobol4j/ +COPY --from=builder /usr/lib/Open-COBOL-ESQL-4j/ /usr/lib/Open-COBOL-ESQL-4j/ +COPY --from=builder /usr/bin/cob-config /usr/bin/cob-config +COPY --from=builder /usr/bin/cobj /usr/bin/cobj +COPY --from=builder /usr/bin/cobj-api /usr/bin/cobj-api +COPY --from=builder /usr/bin/cobj-idx /usr/bin/cobj-idx +COPY --from=builder /usr/bin/cobjrun /usr/bin/cobjrun +COPY --from=builder /usr/bin/ocesql /usr/bin/ocesql +COPY --from=builder /usr/include/libcobj.h /usr/include/libcobj.h +COPY --from=builder /usr/share/opensource-cobol-4j-${opensource_COBOL_4J_version} /usr/share/opensource-cobol-4j-${opensource_COBOL_4J_version} + +# classpath settings +ENV CLASSPATH=:/usr/lib/opensourcecobol4j/libcobj.jar:/usr/lib/Open-COBOL-ESQL-4j/postgresql.jar:/usr/lib/Open-COBOL-ESQL-4j/ocesql4j.jar +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 # add sample programs ADD cobol_sample /root/cobol_sample diff --git a/README.md b/README.md index ce5fbdf..f4f3aa3 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,26 @@ -# opensource COBOL 4J development environment (Docker) +このリポジトリでは、GitHub Actionsを使用して、opensource COBOL 4J及びOpen COBOL ESQL 4JのインストールされたDockerイメージのリリースを行います。 -## Docker image -Versions : +# リリース手順 -- OS: Ubuntu -- opensource COBOL 4J: v1.1.7 -- Open COBOL ESQL 4J: v1.1.1 +## build-config.jsonの編集 -In order to "Hello World" program, run the following commands in the docker container +リリースするバージョンに合わせて、build-config.jsonを編集します。 +* opensource_COBOL_4J_version: Dockerイメージにインストールするopensource COBOL 4Jのバージョン +* Open_COBOL_ESQL_4J_version: DockerイメージにインストールするOpen COBOL ESQL 4Jのバージョン +* version_string_prefix: リリースするDockerイメージタグのプレフィックス + * 例えば20250929を指定すると、以下の3つのタグを持つDockerイメージがビルドされ、Docker Hubにプッシュされます。 + * opensourcecobol/opensourcecobol4j:20250929 + * opensourcecobol/opensourcecobol4j:20250929-utf8 + * opensourcecobol/opensourcecobol4j:latest -``` -cd /root/cobol_sample -cobj HELLO.cbl -java HELLO -``` +## ワークフローの手動実行 -## Docker containers +[公式ドキュメント](https://docs.github.com/ja/actions/how-tos/manage-workflow-runs/manually-run-a-workflow)を参考にして、ワークフローを手動で実行します。 -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. +* ワークフロー名: `Build and Push Docker Image` +* ブランチ: `main` +* 入力パラメータ: `push_to_dockerhub`に`true`を指定 -```bash -cd docker-compose -docker compose up -d -docker attach oc4j_client -``` +これによりDockerイメージがビルドされ、Docker HubにDockerイメージがプッシュされます。 -Run the following in the docker container and execute sample programs of Open COBOL ESQL 4J. - -```bash -cd /root/ocesql4j_sample -make -``` - -Copyright 2021-2024, Tokyo System House Co., Ltd. +Copyright 2021-2025, Tokyo System House Co., Ltd. diff --git a/build-config.json b/build-config.json new file mode 100644 index 0000000..b7e6ada --- /dev/null +++ b/build-config.json @@ -0,0 +1,5 @@ +{ + "opensource_COBOL_4J_version": "1.1.13", + "Open_COBOL_ESQL_4J_version": "1.1.2", + "version_string_prefix": "20250929" +} \ No newline at end of file diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml index fc3c4a9..96f823d 100644 --- a/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -12,7 +12,12 @@ services: - "5432:5432" oc4j_client: - image: opensourcecobol/opensourcecobol4j:20241227 + build: + context: .. + dockerfile: Dockerfile + args: + - opensource_COBOL_4J_version=dummy_value + - Open_COBOL_ESQL_4J_version=dummy_value container_name: oc4j_client stdin_open: true tty: true diff --git a/ocesql4j_sample/Makefile b/ocesql4j_sample/Makefile deleted file mode 100644 index d002e11..0000000 --- a/ocesql4j_sample/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -all: - ocesql INSERTTBL.cbl INSERTTBL.cob - ocesql FETCHTBL.cbl FETCHTBL.cob - cobj *.cob - java INSERTTBL - java FETCHTBL diff --git a/ocesql4j_sample/run.sh b/ocesql4j_sample/run.sh new file mode 100644 index 0000000..0decff5 --- /dev/null +++ b/ocesql4j_sample/run.sh @@ -0,0 +1,5 @@ +ocesql INSERTTBL.cbl INSERTTBL.cob +ocesql FETCHTBL.cbl FETCHTBL.cob +cobj *.cob +java INSERTTBL +java FETCHTBL diff --git a/utf8.Dockerfile b/utf8.Dockerfile index ea3a280..5357d1b 100644 --- a/utf8.Dockerfile +++ b/utf8.Dockerfile @@ -1,29 +1,50 @@ +# Build stage +FROM almalinux:9 AS builder + +ARG opensource_COBOL_4J_version=dummy_value + +SHELL ["/bin/bash", "-c"] + +# install build dependencies +RUN dnf update -y && \ + dnf install -y gcc make bison flex automake autoconf diffutils gettext java-11-openjdk-devel && \ + dnf clean all + +# install sbt +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 + +# build opensourcecobol4j +RUN cd /root && \ + 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 && \ + tar zxvf opensourcecobol4j-v${opensource_COBOL_4J_version}.tar.gz && \ + cd opensourcecobol4j-${opensource_COBOL_4J_version} && \ + mkdir -p /tmp/usr/ &&\ + ./configure --prefix=/tmp/usr/ --enable-utf8 && \ + touch cobj/*.m4 && \ + make && \ + make install && \ + rm -rf /root/opensourcecobol4j-v${opensource_COBOL_4J_version}.tar.gz /root/opensourcecobol4j-${opensource_COBOL_4J_version} + +# Runtime stage FROM almalinux:9 SHELL ["/bin/bash", "-c"] +# install runtime dependencies only +RUN dnf update -y && \ + dnf install -y java-11-openjdk-devel && \ + dnf clean all && \ + rm -rf /var/cache/dnf/* + +# copy built files from builder stage +COPY --from=builder /tmp/usr/ /usr/ + # classpath settings ENV CLASSPATH=:/usr/lib/opensourcecobol4j/libcobj.jar RUN echo 'export CLASSPATH=:/usr/lib/opensourcecobol4j/libcobj.jar' >> ~/.bashrc -# install dependencies -RUN dnf update -y -RUN dnf install -y gcc make bison flex automake autoconf diffutils gettext java-11-openjdk-devel - -# install sbt -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 - -# install opensourcecobol4j -RUN cd /root &&\ - curl -L -o opensourcecobol4j-v1.1.7.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v1.1.7.tar.gz &&\ - tar zxvf opensourcecobol4j-v1.1.7.tar.gz &&\ - cd opensourcecobol4j-1.1.7 &&\ - ./configure --prefix=/usr/ --enable-utf8 &&\ - touch cobj/*.m4 &&\ - make &&\ - make install &&\ - rm /root/opensourcecobol4j-v1.1.7.tar.gz - # add sample programs ADD cobol_sample /root/cobol_sample