Skip to content

Commit e495f99

Browse files
build: introduce multi stage builds
1 parent c0e1a56 commit e495f99

File tree

1 file changed

+66
-37
lines changed

1 file changed

+66
-37
lines changed

Dockerfile

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,78 @@
1-
FROM almalinux:9
1+
# Builder stage
2+
FROM almalinux:9 AS builder
23

34
SHELL ["/bin/bash", "-c"]
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+
# Install build dependencies
7+
RUN dnf update -y && \
8+
dnf install -y gcc make bison flex automake autoconf diffutils gettext java-11-openjdk-devel curl gzip tar && \
9+
dnf clean all
810

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
11+
# Install sbt
12+
RUN curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz | gzip -d > cs && \
13+
chmod +x cs && \
14+
echo Y | ./cs setup
1215

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

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
19+
# Build opensourcecobol4j
20+
RUN cd /tmp && \
21+
curl -L -o opensourcecobol4j-v1.1.7.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v1.1.7.tar.gz && \
22+
tar zxf opensourcecobol4j-v1.1.7.tar.gz && \
23+
cd opensourcecobol4j-1.1.7 && \
24+
./configure --prefix=/usr/ && \
25+
make && \
26+
make install
2527

26-
# Install Open COBOL ESQL 4J
27-
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
42-
43-
# add sample programs
28+
# Build Open COBOL ESQL 4J
29+
RUN mkdir -p /usr/lib/Open-COBOL-ESQL-4j && \
30+
cd /tmp && \
31+
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 && \
32+
tar zxf Open-COBOL-ESQL-4j-1.1.1.tar.gz && \
33+
cd Open-COBOL-ESQL-4j-1.1.1 && \
34+
curl -L -o /usr/lib/Open-COBOL-ESQL-4j/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.2.24.jar && \
35+
cp /usr/lib/opensourcecobol4j/libcobj.jar dblibj/lib && \
36+
cp /usr/lib/Open-COBOL-ESQL-4j/postgresql.jar dblibj/lib && \
37+
./configure --prefix=/usr/ && \
38+
make && \
39+
make install
40+
41+
# Runtime stage
42+
FROM almalinux:9
43+
44+
SHELL ["/bin/bash", "-c"]
45+
46+
# Install only runtime dependencies
47+
RUN dnf update -y && \
48+
dnf install -y java-11-openjdk-headless && \
49+
dnf clean all
50+
51+
# Copy installed files from builder
52+
# Copy opensourcecobol4j executables
53+
COPY --from=builder /usr/bin/cobj /usr/bin/
54+
COPY --from=builder /usr/bin/cobjrun /usr/bin/
55+
COPY --from=builder /usr/bin/cob-config /usr/bin/
56+
COPY --from=builder /usr/bin/cobj-idx /usr/bin/
57+
COPY --from=builder /usr/bin/cobj-api /usr/bin/
58+
# Copy Open COBOL ESQL 4J executable
59+
COPY --from=builder /usr/bin/ocesql4j /usr/bin/
60+
# Copy JAR libraries
61+
COPY --from=builder /usr/lib/opensourcecobol4j/ /usr/lib/opensourcecobol4j/
62+
COPY --from=builder /usr/lib/Open-COBOL-ESQL-4j/ /usr/lib/Open-COBOL-ESQL-4j/
63+
# Copy configuration and copy files
64+
COPY --from=builder /usr/share/opensource-cobol-4j-1.1.8-hotfix1/ /usr/share/opensource-cobol-4j-1.1.8-hotfix1/
65+
# Copy header file
66+
COPY --from=builder /usr/include/libcobj.h /usr/include/
67+
68+
# Set classpath
69+
ENV CLASSPATH=:/usr/lib/opensourcecobol4j/libcobj.jar:/usr/lib/Open-COBOL-ESQL-4j/postgresql.jar:/usr/lib/Open-COBOL-ESQL-4j/ocesql4j.jar
70+
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
71+
72+
# Add sample programs
4473
ADD cobol_sample /root/cobol_sample
4574
ADD ocesql4j_sample /root/ocesql4j_sample
4675

4776
WORKDIR /root/
4877

49-
CMD ["/bin/bash"]
78+
CMD ["/bin/bash"]

0 commit comments

Comments
 (0)