-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
125 lines (113 loc) · 4.82 KB
/
Dockerfile
File metadata and controls
125 lines (113 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# ============================================================
# MainFreem — Environnement Docker COBOL v2.0
# GNU COBOL 4.0 + ocesql + PostgreSQL client
# ============================================================
# Exercices 1-9 & 13-15 : GNU COBOL seul
# Exercices 10-12 : ocesql + PostgreSQL (docker-compose)
# ============================================================
FROM debian:bookworm-slim
LABEL maintainer="samarha-dev"
LABEL description="COBOL learning environment: GNU COBOL 4.0 + ocesql + PostgreSQL client"
LABEL version="2.0"
ENV DEBIAN_FRONTEND=noninteractive
ENV PGHOST=postgres
ENV PGPORT=5432
ENV PGDATABASE=coboldb
ENV PGUSER=cobol
ENV PGPASSWORD=cobol123
# ── Dépendances système ──────────────────────────────────────
RUN apt-get update && apt-get install -y --no-install-recommends \
gnucobol4 \
build-essential \
autoconf \
automake \
libtool \
pkg-config \
git \
libpq-dev \
postgresql-client \
curl \
vim \
nano \
less \
&& rm -rf /var/lib/apt/lists/*
# ── Compilation d'ocesql depuis les sources ──────────────────
RUN git clone --depth=1 https://github.com/tafujino/ocesql.git /tmp/ocesql \
&& cd /tmp/ocesql \
&& autoreconf -i \
&& ./configure --prefix=/usr/local \
&& make -j"$(nproc)" \
&& make install \
&& ldconfig \
&& rm -rf /tmp/ocesql
WORKDIR /workspace
COPY examples/ /workspace/examples/
# ── Script compile.sh ─────────────────────────────────────────
RUN cat > /usr/local/bin/compile.sh << 'EOF'
#!/bin/bash
set -e
if [ $# -eq 0 ]; then
echo "Usage: compile.sh <fichier.cobol|fichier.pco> [-run]"
exit 1
fi
FILE=$1
BASENAME="${FILE%.*}"
EXT="${FILE##*.}"
RUN_AFTER=false
[ "$2" = "-run" ] && RUN_AFTER=true
if [ "$EXT" = "pco" ] || [ "$EXT" = "sqb" ]; then
echo "→ Précompilation ESQL avec ocesql..."
ocesql "$FILE" "${BASENAME}.cob"
echo "→ Compilation GNU COBOL avec libpq..."
cobc -x "${BASENAME}.cob" -locesql -lpq -o "${BASENAME}"
echo "✓ Binaire : ./${BASENAME}"
else
echo "→ Compilation GNU COBOL..."
cobc -x "$FILE" -o "${BASENAME}"
echo "✓ Binaire : ./${BASENAME}"
fi
$RUN_AFTER && "./${BASENAME}"
EOF
RUN chmod +x /usr/local/bin/compile.sh
# ── Script check-env.sh ───────────────────────────────────────
RUN cat > /usr/local/bin/check-env.sh << 'EOF'
#!/bin/bash
echo "════════════════════════════════════════════"
echo " MainFreem — Vérification de l'environnement"
echo "════════════════════════════════════════════"
echo ""
echo "📦 GNU COBOL :"
cobc --version | head -1
echo ""
echo "📦 ocesql :"
ocesql --version 2>/dev/null || echo " ⚠️ Non trouvé"
echo ""
echo "📦 PostgreSQL client :"
psql --version
echo ""
echo "🔌 Connexion PostgreSQL :"
if psql -c "SELECT 1;" > /dev/null 2>&1; then
echo " ✅ Connecté à ${PGHOST}:${PGPORT}/${PGDATABASE}"
else
echo " ⚠️ Non connecté (normal sans docker-compose)"
fi
echo ""
echo "════════════════════════════════════════════"
EOF
RUN chmod +x /usr/local/bin/check-env.sh
# ── Message de bienvenue ──────────────────────────────────────
RUN echo '\n\
╔══════════════════════════════════════════════════════╗\n\
║ MainFreem — Environnement Docker COBOL ║\n\
║ GNU COBOL 4.0 + ocesql + PostgreSQL ║\n\
╠══════════════════════════════════════════════════════╣\n\
║ check-env.sh → vérifier l'\''environnement║\n\
║ compile.sh prog.cobol → compiler COBOL ║\n\
║ compile.sh prog.pco → compiler COBOL+SQL ║\n\
║ compile.sh prog.pco -run → compiler et exécuter ║\n\
║ ║\n\
║ Exercices : /workspace/exercises/ ║\n\
║ Exemples : /workspace/examples/ ║\n\
╚══════════════════════════════════════════════════════╝\n'\
>> /etc/bash.bashrc
CMD ["bash"]