Skip to content

Introduce multi stage builds #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 66 additions & 37 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,78 @@
FROM almalinux:9
# Builder stage
FROM almalinux:9 AS builder

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

# 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
# Install build dependencies
RUN dnf update -y && \
dnf install -y gcc make bison flex automake autoconf diffutils gettext java-11-openjdk-devel gzip tar && \
dnf clean all

# 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 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
# Set PATH for sbt
ENV PATH="$PATH:/root/.local/share/coursier/bin"

# 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
# Build opensourcecobol4j
RUN cd /tmp && \
curl -L -o opensourcecobol4j-v1.1.9.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v1.1.9.tar.gz && \
tar zxf opensourcecobol4j-v1.1.9.tar.gz && \
cd opensourcecobol4j-1.1.9 && \
./configure --prefix=/usr/ && \
make && \
make install

# Install 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

# add sample programs
# Build Open COBOL ESQL 4J
RUN mkdir -p /usr/lib/Open-COBOL-ESQL-4j && \
cd /tmp && \
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 zxf Open-COBOL-ESQL-4j-1.1.1.tar.gz && \
cd Open-COBOL-ESQL-4j-1.1.1 && \
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

# Runtime stage
FROM almalinux:9

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

# Install only runtime dependencies
RUN dnf update -y && \
dnf install -y java-11-openjdk-headless && \
dnf clean all

# Copy installed files from builder
# Copy opensourcecobol4j executables
COPY --from=builder /usr/bin/cobj /usr/bin/
COPY --from=builder /usr/bin/cobjrun /usr/bin/
COPY --from=builder /usr/bin/cob-config /usr/bin/
COPY --from=builder /usr/bin/cobj-idx /usr/bin/
COPY --from=builder /usr/bin/cobj-api /usr/bin/
# Copy Open COBOL ESQL 4J executable
COPY --from=builder /usr/bin/ocesql /usr/bin/
# Copy JAR libraries
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 configuration and copy files
COPY --from=builder /usr/share/opensource-cobol-4j-1.1.9/ /usr/share/opensource-cobol-4j-1.1.9/
# Copy header file
COPY --from=builder /usr/include/libcobj.h /usr/include/

# Set classpath
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
ADD ocesql4j_sample /root/ocesql4j_sample

WORKDIR /root/

CMD ["/bin/bash"]
CMD ["/bin/bash"]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# opensource COBOL 4J development environment (Docker)

## Docker image

Versions :

- OS: Ubuntu
- opensource COBOL 4J: v1.1.7
- opensource COBOL 4J: v1.1.9
- Open COBOL ESQL 4J: v1.1.1

In order to "Hello World" program, run the following commands in the docker container
Expand Down
71 changes: 51 additions & 20 deletions utf8.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,63 @@
# Builder stage
FROM almalinux:9 AS builder

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 gzip tar && \
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

# Set PATH for sbt
ENV PATH="$PATH:/root/.local/share/coursier/bin"

# Build opensourcecobol4j with UTF-8 support
RUN cd /tmp && \
curl -L -o opensourcecobol4j-v1.1.9.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v1.1.9.tar.gz && \
tar zxf opensourcecobol4j-v1.1.9.tar.gz && \
cd opensourcecobol4j-1.1.9 && \
./configure --prefix=/usr/ --enable-utf8 && \
touch cobj/*.m4 && \
make && \
make install

# Runtime stage
FROM almalinux:9

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

# classpath settings
# Install only runtime dependencies
RUN dnf update -y && \
dnf install -y java-11-openjdk-headless && \
dnf clean all

# Copy installed files from builder
# Copy opensourcecobol4j executables
COPY --from=builder /usr/bin/cobj /usr/bin/
COPY --from=builder /usr/bin/cobjrun /usr/bin/
COPY --from=builder /usr/bin/cob-config /usr/bin/
COPY --from=builder /usr/bin/cobj-idx /usr/bin/
COPY --from=builder /usr/bin/cobj-api /usr/bin/
# Copy JAR libraries
COPY --from=builder /usr/lib/opensourcecobol4j/ /usr/lib/opensourcecobol4j/
# Copy configuration and copy files
COPY --from=builder /usr/share/opensource-cobol-4j-1.1.9/ /usr/share/opensource-cobol-4j-1.1.9/
# Copy header file
COPY --from=builder /usr/include/libcobj.h /usr/include/

# Set classpath
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 sample programs
ADD cobol_sample /root/cobol_sample

WORKDIR /root/

CMD ["/bin/bash"]