From f091ed582d48aa6989a965cd599e21cb3246bfb0 Mon Sep 17 00:00:00 2001 From: Max Meinhold Date: Sat, 23 Jan 2021 22:12:28 -0500 Subject: [PATCH 1/3] Create codespaces configuration Allows for easy dev setup by installing dependencies, setting up a db, and updating the db revision for you (pending codespaces GA) --- .devcontainer/Dockerfile | 9 +++++ .devcontainer/devcontainer.json | 59 +++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yaml | 40 +++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yaml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..14700aff --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,9 @@ +FROM mcr.microsoft.com/vscode/devcontainers/universal:1-linux + +USER root + +# Add LDAP and python dependency build deps +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \ + apt-get -yq --no-install-recommends install gcc curl libsasl2-dev libldap2-dev libssl-dev python3-dev + +USER codespace diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..64317602 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,59 @@ +// Update the VARIANT arg in docker-compose.yml to pick a Python version: 3, 3.8, 3.7, 3.6 +{ + "name": "Packet Codespace (python and postgres)", + "dockerComposeFile": "docker-compose.yaml", + "service": "app", + "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind" ], + + // Set *default* container specific settings.json values on container create. + "settings": { + "sqltools.connections": [{ + "name": "Container database", + "driver": "PostgreSQL", + "previewLimit": 50, + "server": "localhost", + "port": 5432, + "database": "postgres", + "username": "postgres", + "password": "mysecretpassword" + }], + "terminal.integrated.shell.linux": "/bin/bash", + "python.pythonPath": "/opt/python/latest/bin/python", + "python.linting.enabled": true, + "python.linting.pylintEnabled": true, + "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", + "python.formatting.blackPath": "/usr/local/py-utils/bin/black", + "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", + "python.linting.banditPath": "/usr/local/py-utils/bin/bandit", + "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", + "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", + "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", + "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", + "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint", + "python.testing.pytestPath": "/usr/local/py-utils/bin/pytest" + }, + "remoteUser": "codespace", + "overrideCommand": false, + "workspaceMount": "source=${localWorkspaceFolder},target=/home/codespace/workspace,type=bind,consistency=cached", + "workspaceFolder": "/home/codespace/workspace", + "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined", "--privileged", "--init" ], + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "GitHub.vscode-pull-request-github", + "ms-python.python", + "mtxr.sqltools", + "mtxr.sqltools-driver-pg" + ], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [5000, 5432], + + // Use 'postCreateCommand' to run commands after the container is created. + // "oryx build" will automatically install your dependencies and attempt to build your project + "postCreateCommand": [ + "pip install --progress-bar=off install -r requirements.txt;", + "yarn install && `yarn bin gulp production`;", + "/home/codespace/.local/bin/flask db upgrade;" + ] +} diff --git a/.devcontainer/docker-compose.yaml b/.devcontainer/docker-compose.yaml new file mode 100644 index 00000000..1f379560 --- /dev/null +++ b/.devcontainer/docker-compose.yaml @@ -0,0 +1,40 @@ +version: '3' + +services: + app: + build: + context: .. + dockerfile: .devcontainer/Dockerfile + args: + NODE_VERSION: "10" + + 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: codespace + + # 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: mysecretpassword + + # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward MongoDB locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + +volumes: + postgres-data: From 56dbf5bb5f9178b20994b59fbd182dd83c1cb36b Mon Sep 17 00:00:00 2001 From: Max Meinhold Date: Sat, 23 Jan 2021 22:07:29 -0500 Subject: [PATCH 2/3] Add `apt update` to python linting --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 71dcdd5c..3bdac3f6 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Install ldap dependencies - run: sudo apt-get install libldap2-dev libsasl2-dev + run: sudo apt-get update && sudo apt-get install libldap2-dev libsasl2-dev - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 From dcc1a0847743cadd76b36892ecedf311ca50bf63 Mon Sep 17 00:00:00 2001 From: Max Meinhold Date: Sun, 24 Jan 2021 20:26:48 -0500 Subject: [PATCH 3/3] Mount docker socket via compose --- .devcontainer/devcontainer.json | 1 - .devcontainer/docker-compose.yaml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 64317602..ef33dc3b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,7 +3,6 @@ "name": "Packet Codespace (python and postgres)", "dockerComposeFile": "docker-compose.yaml", "service": "app", - "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind" ], // Set *default* container specific settings.json values on container create. "settings": { diff --git a/.devcontainer/docker-compose.yaml b/.devcontainer/docker-compose.yaml index 1f379560..974d59f2 100644 --- a/.devcontainer/docker-compose.yaml +++ b/.devcontainer/docker-compose.yaml @@ -9,6 +9,7 @@ services: NODE_VERSION: "10" volumes: + - /var/run/docker.sock:/var/run/docker.sock - ..:/workspace:cached # Overrides default command so things don't shut down after the process ends.