From 4fb280c97fd069f761377c0c76a4cc92823a1417 Mon Sep 17 00:00:00 2001 From: yutaro-sakamoto <80912876+yutaro-sakamoto@users.noreply.github.com> Date: Sun, 3 Nov 2024 16:23:47 +0900 Subject: [PATCH] Add Visual Studio Code Dev Container (#107) --- .devcontainer/Dockerfile | 15 +++++++++++ .devcontainer/boot.sh | 27 ++++++++++++++++++++ .devcontainer/devcontainer.json | 7 ++++++ .devcontainer/docker-compose.yml | 28 +++++++++++++++++++++ .devcontainer/term_settings/extra_bashrc.sh | 11 ++++++++ .devcontainer/term_settings/pre-commit | 4 +++ 6 files changed, 92 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100755 .devcontainer/boot.sh create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .devcontainer/term_settings/extra_bashrc.sh create mode 100755 .devcontainer/term_settings/pre-commit diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..eb36cb4 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,15 @@ +FROM almalinux:9 + +SHELL ["/bin/bash", "-c"] + +# classpath settings +ENV CLASSPATH :/usr/lib/opensourcecobol4j/libcobj.jar:/usr/lib/Open-COBOL-ESQL-4j/ocesql4j.jar:/usr/lib/Open-COBOL-ESQL-4j/postgresql.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 dependencies +RUN dnf update -y +RUN dnf install -y epel-release +RUN dnf install -y gcc make bison flex automake autoconf diffutils gettext java-21-openjdk-devel git-clang-format cppcheck libtool gettext-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 diff --git a/.devcontainer/boot.sh b/.devcontainer/boot.sh new file mode 100755 index 0000000..c7b626a --- /dev/null +++ b/.devcontainer/boot.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Install opensource COBOL 4J +cd opensourcecobol4j/ +./configure --prefix=/usr/ +make +make install +cd ../ + +# Install Open COBOL ESQL 4J +cp /usr/lib/opensourcecobol4j/libcobj.jar dblibj/lib/ +cp /usr/lib/opensourcecobol4j/libcobj.jar dblibj/lib/ +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/Open-COBOL-ESQL-4j/postgresql.jar dblibj/lib/ +./configure --prefix=/usr/ +make +make install + +# Set up git config +git config --global --add safe.directory /workspaces/Open-COBOL-ESQL-4j + +# Set up pre-commit hook +cp .devcontainer/term_settings/pre-commit .git/hooks/pre-commit + +# Set up ~/.bashrc +cat .devcontainer/term_settings/extra_bashrc.sh >> ~/.bashrc \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..aba41b1 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,7 @@ +{ + "name": "Open COBOL ESQL 4J development", + "dockerComposeFile": "docker-compose.yml", + "service": "oc4j_client", + "workspaceFolder": "/workspaces/Open-COBOL-ESQL-4j", + "postCreateCommand": ".devcontainer/boot.sh" +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..8a2d306 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,28 @@ +version: '3' + +services: + oc4j_db: + image: postgres:13 + container_name: oc4j_db + environment: + - POSTGRES_USER=main_user + - POSTGRES_PASSWORD=password + - POSTGRES_DB=testdb + ports: + - "5432:5432" + + oc4j_client: + image: oc4j_client + container_name: oc4j_client + build: + context: . + dockerfile: Dockerfile + stdin_open: true + volumes: + - ../..:/workspaces:cached + tty: true + depends_on: + oc4j_db: + condition: service_started + logging: + driver: none diff --git a/.devcontainer/term_settings/extra_bashrc.sh b/.devcontainer/term_settings/extra_bashrc.sh new file mode 100644 index 0000000..f1d4274 --- /dev/null +++ b/.devcontainer/term_settings/extra_bashrc.sh @@ -0,0 +1,11 @@ +alias ls='ls --color=auto' +alias ll='ls -l' +alias la='ls -a' + +alias g='git' + +parse_git_branch() { + git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' +} + +export PS1="\e[0;32m[\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\e[0;32m]\033[00m " diff --git a/.devcontainer/term_settings/pre-commit b/.devcontainer/term_settings/pre-commit new file mode 100755 index 0000000..8effe07 --- /dev/null +++ b/.devcontainer/term_settings/pre-commit @@ -0,0 +1,4 @@ +#!/bin/bash + +./format +git add -u \ No newline at end of file