From 137cd3dabaa0776b973dacc4d381c8fcb8510e2f Mon Sep 17 00:00:00 2001 From: Inge Amlien Date: Thu, 16 May 2024 11:08:07 +0200 Subject: [PATCH] Devcontainer (#63) * Add universal devcontainer image, install R. * Add "postCreateCommand": "make" --- .devcontainer/Dockerfile | 29 ++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 27 ++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..e92fa0a --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,29 @@ +FROM mcr.microsoft.com/vscode/devcontainers/universal:1.7.5-linux + +# Set environment variables to avoid interactive prompts during package installation +ENV DEBIAN_FRONTEND=noninteractive + +# # Update and install necessary packages +RUN apt-get update && \ + apt-get install -y \ + software-properties-common \ + wget \ + gnupg2 \ + lsb-release \ + apt-transport-https \ + ca-certificates \ + libcurl4-openssl-dev \ + libssl-dev \ + libxml2-dev + +# # Install R +RUN apt-get install -y r-base + +# # Install PHP +# RUN add-apt-repository ppa:ondrej/php && \ +# apt-get update && \ +# apt-get install -y php7.4 + +# # Install Lighttpd +# RUN apt-get update && \ +# apt-get install -y lighttpd diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..4b101bf --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,27 @@ +{ + "name": "Universal with PostgreSQL", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + // "ghcr.io/shyim/devcontainers-features/php:latest": { + // "version": "7.4", + // "extensionsExtra": "xdebug redis" + // } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // This can be used to network with other containers or the host. + // "forwardPorts": [5000, 5432], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "make" + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..f2e9705 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,35 @@ +version: '3.8' + +services: + app: + build: + context: .. + dockerfile: .devcontainer/Dockerfile + + volumes: + - ../..:/workspaces: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 + + # 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: + image: postgres:latest + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + environment: + POSTGRES_USER: postgres + POSTGRES_DB: postgres + POSTGRES_PASSWORD: postgres + + # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + +volumes: + postgres-data: