Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add devcontainer #103

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .devcontainer/couchdb.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
; CouchDB Configuration Settings

; Custom settings should be made in this file. They will override settings
; in default.ini, but unlike changes made to default.ini, this file won't be
; overwritten on server upgrade.

[couchdb]
;max_document_size = 4294967296 ; bytes
;os_process_timeout = 5000

[couch_peruser]
; If enabled, couch_peruser ensures that a private per-user database
; exists for each document in _users. These databases are writable only
; by the corresponding user. Databases are in the following form:
; userdb-{hex encoded username}
;enable = true

; If set to true and a user is deleted, the respective database gets
; deleted as well.
;delete_dbs = true

; Set a default q value for peruser-created databases that is different from
; cluster / q
;q = 1

[chttpd]
;port = 5984
;bind_address = localhost

; Options for the MochiWeb HTTP server.
;server_options = [{backlog, 128}, {acceptor_pool_size, 16}]

; For more socket options, consult Erlang's module 'inet' man page.
;socket_options = [{sndbuf, 262144}, {nodelay, true}]

enable_cors=true

[httpd]
; NOTE that this only configures the "backend" node-local port, not the
; "frontend" clustered port. You probably don't want to change anything in
; this section.
; Uncomment next line to trigger basic-auth popup on unauthorized requests.
;WWW-Authenticate = Basic realm="administrator"

; Uncomment next line to set the configuration modification whitelist. Only
; whitelisted values may be changed via the /_config URLs. To allow the admin
; to change this value over HTTP, remember to include {httpd,config_whitelist}
; itself. Excluding it from the list would require editing this file to update
; the whitelist.
;config_whitelist = [{httpd,config_whitelist}, {log,level}, {etc,etc}]

[cors]
origins = *
methods = GET, PUT, POST, HEAD, DELETE
credentials = true
headers = accept, authorization, content-type, origin, referer, x-csrf-token


[ssl]
;enable = true
;cert_file = /full/path/to/server_cert.pem
;key_file = /full/path/to/server_key.pem
;password = somepassword

; set to true to validate peer certificates
;verify_ssl_certificates = false

; Set to true to fail if the client does not send a certificate. Only used if verify_ssl_certificates is true.
;fail_if_no_peer_cert = false

; Path to file containing PEM encoded CA certificates (trusted
; certificates used for verifying a peer certificate). May be omitted if
; you do not want to verify the peer.
;cacert_file = /full/path/to/cacertf

; The verification fun (optional) if not specified, the default
; verification fun will be used.
;verify_fun = {Module, VerifyFun}

; maximum peer certificate depth
;ssl_certificate_max_depth = 1

; Reject renegotiations that do not live up to RFC 5746.
;secure_renegotiate = true

; The cipher suites that should be supported.
; Can be specified in erlang format "{ecdhe_ecdsa,aes_128_cbc,sha256}"
; or in OpenSSL format "ECDHE-ECDSA-AES128-SHA256".
;ciphers = ["ECDHE-ECDSA-AES128-SHA256", "ECDHE-ECDSA-AES128-SHA"]

; The SSL/TLS versions to support
;tls_versions = [tlsv1, 'tlsv1.1', 'tlsv1.2']

; To enable Virtual Hosts in CouchDB, add a vhost = path directive. All requests to
; the Virtual Host will be redirected to the path. In the example below all requests
; to http://example.com/ are redirected to /database.
; If you run CouchDB on a specific port, include the port number in the vhost:
; example.com:5984 = /database
[vhosts]
;example.com = /database/

; To create an admin account uncomment the '[admins]' section below and add a
; line in the format 'username = password'. When you next start CouchDB, it
; will change the password to a hash (so that your passwords don't linger
; around in plain-text files). You can add more admin accounts with more
; 'username = password' lines. Don't forget to restart CouchDB after
; changing this.
[admins]
dev = dev
42 changes: 42 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "Ubuntu",
"build": {
"dockerfile": "../Dockerfile"
// ./database/couchdb.ini:/opt/couchdb/etc/local.ini
},
"forwardPorts": [
5984 // API
],

"postCreateCommand": "bash ./.devcontainer/postcreate.sh",
"postAttachCommand": "bash ./.devcontainer/postattach.sh",
"customizations": {
"vscode": {
"extensions": [
"rvest.vs-code-prettier-eslint",
"dbaeumer.vscode-eslint",
"codeandstuff.package-json-upgrade",
"tamasfe.even-better-toml",
"nefrob.vscode-just-syntax",
"ms-python.python",
"ms-python.debugpy",
"charliermarsh.ruff",
"mhutchie.git-graph",
"njpwerner.autodocstring",
"bungcip.better-toml",
"esbenp.prettier-vscode"
],
"settings": {
"terminal.integrated.detectLocale": "off"
}
}
},
"runArgs": [
"-e",
"DISPLAY=${localEnv:DISPLAY}", // Wayland socket endpoint
"-v",
"/tmp/.X11-unix:/tmp/.X11-unix", // X11 socket
"--hostname",
"hardpy-devcontainer"
]
}
8 changes: 8 additions & 0 deletions .devcontainer/postattach.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pip3 install --upgrade pip

pip3 install -e .[dev]
cd hardpy/hardpy_panel/frontend
corepack enable
corepack prepare yarn@4.0.1 --activate
yarn set version 4.0.1
corepack yarn install
28 changes: 28 additions & 0 deletions .devcontainer/postcreate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

sudo chown $(whoami):$(whoami) /workspaces

sudo apt update
sudo apt install -y \
curl \
apt-transport-https \
gnupg

curl https://couchdb.apache.org/repo/keys.asc | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/couchdb-archive-keyring.gpg > /dev/null 2>&1

. /etc/os-release

echo "deb [signed-by=/usr/share/keyrings/couchdb-archive-keyring.gpg] https://apache.jfrog.io/artifactory/couchdb-deb/ ${VERSION_CODENAME} main" \
| sudo tee /etc/apt/sources.list.d/couchdb.list > /dev/null

sudo apt update

sudo apt-get install -y couchdb

sudo cp .devcontainer/couchdb.ini /opt/couchdb/etc/local.ini

sudo service couchdb start

sudo service couchdb stop
61 changes: 61 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
FROM ubuntu:22.04 AS build-env

USER root

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
<<EOR
apt-get update && \
apt-get install -y --no-install-recommends \
curl \
ca-certificates \
gnupg \
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y --no-install-recommends nodejs \
&& rm -rf /var/lib/apt/lists/*
EOR

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
<<EOR
apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
devscripts \
lintian \
debhelper \
fakeroot \
dh-python \
pybuild-plugin-pyproject \
python3-minimal \
python3-hatchling \
python3-pip \
python3-venv \
sudo \
gpg \
wget \
git \
net-tools \
&& rm -rf /var/lib/apt/lists/*
EOR

RUN corepack enable && yarn init -2

FROM build-env AS dev-env

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
<<EOR
apt-get update && \
apt-get install -y --no-install-recommends \
openssh-client \
sudo \
&& rm -rf /var/lib/apt/lists/*
EOR

ARG USERNAME=ubuntu

RUN <<EOR
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME && \
chmod 0440 /etc/sudoers.d/$USERNAME
EOR
40 changes: 40 additions & 0 deletions docs/about/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,46 @@ Addresses:
- HardPy panel: http://localhost:8000/
- CouchDB: http://localhost:5984/_utils/

## Dev Container

Ensure that Docker is running and functioning correctly before starting the container build.

### Step 1: Build the Container

1. Open the project in Visual Studio Code (VSCode).
2. Press `Ctrl+Shift+P` to open the command palette.
3. Type and select the command: **Dev Containers: Rebuild Container**.
4. Wait for the container build process to complete.

### Step 2: Configure CouchDB

During the container build, CouchDB will be installed. You will be prompted with configuration questions:

- You can respond arbitrarily to most questions (for example, by entering `1`).
- **Important**: For the question **"CouchDB interface bind address:"**, you must respond with `0.0.0.0`.

### Step 3: Run the Project

After successfully building the container, you can work with the project as usual. The following methods are available for running the project:

#### Running via Script
- Use the `recompile_front.sh` script to rebuild and run the frontend.
- Execute the command in the terminal:
```bash
hardpy run [example]
```

#### Running via VSCode Configurations
- The following run configurations are available in VSCode:
- **Run Frontend**
- **Debug Frontend**
- Any of the examples with the addition of the argument:
```json
"env": {
"DEBUG_FRONTEND": "1"
}
```

## Documentation

### Server
Expand Down