From ca22827a289611e12b8c945f291dbb6cba804fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Cl=C3=A9ment?= Date: Wed, 25 May 2022 12:54:11 +0000 Subject: [PATCH] :hammer: Add dev container --- .devcontainer/Dockerfile | 23 +++++++++++++++ .devcontainer/devcontainer.json | 30 ++++++++++++++++++++ .devcontainer/docker-compose.yml | 48 ++++++++++++++++++++++++++++++++ .gitignore | 6 +++- .vscode/launch.json | 17 +++++++++++ 5 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .vscode/launch.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..cdc7952 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,23 @@ +# [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster +ARG VARIANT=11-bullseye +FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT} + +# [Option] Install Maven +ARG INSTALL_MAVEN="false" +ARG MAVEN_VERSION="" +# [Option] Install Gradle +ARG INSTALL_GRADLE="false" +ARG GRADLE_VERSION="" +RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \ + && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi + +# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 +ARG NODE_VERSION="none" +RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..09881c4 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,30 @@ +{ + "name": "Java & Mariadb", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspace", + + // Set *default* container specific settings.json values on container create. + "settings": { + "java.jdt.ls.java.home": "/docker-java-home" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "vscjava.vscode-java-pack", + "pivotal.vscode-boot-dev-pack", + "richardwillis.vscode-gradle-extension-pack", + "eamodio.gitlens", + "donjayamanne.githistory" + ], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // This can be used to network with other containers or with the host. + // "forwardPorts": [5432], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "java -version", + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..f5079f7 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,48 @@ +version: '3.8' + +volumes: + mysql-data: +services: + app: + container_name: javadev + build: + context: . + dockerfile: Dockerfile + args: + # Update 'VARIANT' to pick an version of Java: 11, 17. + # Append -bullseye or -buster to pin to an OS version. + # Use -bullseye variants on local arm64/Apple Silicon. + VARIANT: "17" + # Options + INSTALL_MAVEN: "false" + MAVEN_VERSION: "" + INSTALL_GRADLE: "true" + GRADLE_VERSION: "7.4.2" + NODE_VERSION: "lts/*" + volumes: + - ..:/workspace:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:db + # Uncomment the next line to use a non-root user for all processes. + # user: vscode + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + db: + container_name: database + image: mariadb:latest + restart: unless-stopped + volumes: + - mysql-data:/var/lib/mysql + environment: + MARIADB_ROOT_PASSWORD: mariadb_root + MARIADB_PASSWORD: claptrap + MARIADB_USER: claptrap + MARIADB_DATABASE: claptrap + # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) diff --git a/.gitignore b/.gitignore index 4d265fe..e38ccbd 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,8 @@ src/main/resources/static/error/js **.log -.jpb/ \ No newline at end of file +.jpb/ + +**/*.env + +bin/ \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e66ba23 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Launch MainBot", + "request": "launch", + "mainClass": "net.Broken.MainBot", + "projectName": "ClaptrapBot", + "envFile": "${workspaceFolder}/.env" + }, + + ] +} \ No newline at end of file