From 13555d1e882e272d3e57999d5777db2f3dd1043d Mon Sep 17 00:00:00 2001 From: Eric Boehs Date: Tue, 26 Mar 2024 15:24:41 -0500 Subject: [PATCH] Create neovim/tmux/zsh devcontainer variant --- .devcontainer/devcontainer.json | 8 +-- .../neovim-tmux-zsh/devcontainer.json | 70 +++++++++++++++++++ .devcontainer/neovim-tmux-zsh/post-create.sh | 65 +++++++++++++++++ .devcontainer/neovim-tmux-zsh/post-start.sh | 9 +++ .devcontainer/post-create.sh | 14 ---- 5 files changed, 145 insertions(+), 21 deletions(-) create mode 100644 .devcontainer/neovim-tmux-zsh/devcontainer.json create mode 100644 .devcontainer/neovim-tmux-zsh/post-create.sh create mode 100644 .devcontainer/neovim-tmux-zsh/post-start.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 374061f7656..69f4e6059e0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -11,13 +11,7 @@ }, "ghcr.io/devcontainers-contrib/features/redis-homebrew:1": { "version": "6.2" - }, - "ghcr.io/devcontainers/features/sshd:1": { - "version": "latest" - }, - "ghcr.io/devcontainers/features/common-utils:2": { }, - "ghcr.io/devcontainers-contrib/features/neovim-homebrew:1": { }, - "ghcr.io/devcontainers-contrib/features/tmux-homebrew:1": { } + } }, "forwardPorts": [ diff --git a/.devcontainer/neovim-tmux-zsh/devcontainer.json b/.devcontainer/neovim-tmux-zsh/devcontainer.json new file mode 100644 index 00000000000..374061f7656 --- /dev/null +++ b/.devcontainer/neovim-tmux-zsh/devcontainer.json @@ -0,0 +1,70 @@ +{ + "name": "vets-api native setup", + "image": "mcr.microsoft.com/devcontainers/base:bullseye", + + "features": { + "ghcr.io/devcontainers-contrib/features/ruby-asdf:0": { + "version": "3.2.3" + }, + "ghcr.io/robbert229/devcontainer-features/postgresql-client:1": { + "version": "15" + }, + "ghcr.io/devcontainers-contrib/features/redis-homebrew:1": { + "version": "6.2" + }, + "ghcr.io/devcontainers/features/sshd:1": { + "version": "latest" + }, + "ghcr.io/devcontainers/features/common-utils:2": { }, + "ghcr.io/devcontainers-contrib/features/neovim-homebrew:1": { }, + "ghcr.io/devcontainers-contrib/features/tmux-homebrew:1": { } + }, + + "forwardPorts": [ + 3000, + 9293, + 5432, + 6379 + ], + "portsAttributes": { + "3000": { + "label": "vets-api", + "onAutoForward": "notify", + "requireLocalPort": true + }, + "9293": { + "label": "vets-api-healthcheck", + "onAutoForward": "silent", + "requireLocalPort": true + }, + "5432": { + "label": "postgis", + "onAutoForward": "silent", + "requireLocalPort": true + }, + "6379": { + "label": "redis", + "onAutoForward": "silent", + "requireLocalPort": true + } + }, + + "postCreateCommand": "sh .devcontainer/post-create.sh", + "postStartCommand": "sh .devcontainer/post-start.sh", + + "customizations": { + "codespaces": { + "repositories": { + "department-of-veterans-affairs/vets-api-mockdata": { + "permissions": { + "contents": "read", + "pull_requests": "write" + } + } + } + }, + "vscode": { + "extensions": ["ms-azuretools.vscode-docker", "Shopify.ruby-lsp"] + } + } +} diff --git a/.devcontainer/neovim-tmux-zsh/post-create.sh b/.devcontainer/neovim-tmux-zsh/post-create.sh new file mode 100644 index 00000000000..20bb30340b8 --- /dev/null +++ b/.devcontainer/neovim-tmux-zsh/post-create.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# Add welcome message +sudo cp .devcontainer/welcome.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt + +# Switch to vets-api ruby version +export PATH="${HOME}/.asdf/shims:${HOME}/.asdf/bin:${PATH}" +asdf install ruby $( cat .ruby-version ) +asdf global ruby $( cat .ruby-version ) + +git clone https://github.com/department-of-veterans-affairs/vets-api-mockdata.git ../vets-api-mockdata + +sudo apt update +sudo apt install -y libpq-dev pdftk shared-mime-info postgresql-15-postgis-3 + +# Add tmux config +if [ ! -f $HOME/.tmux.conf ]; then + cat <> $HOME/.tmux.conf +set -g @plugin 'tmux-plugins/tpm' +set -g @plugin 'tmux-plugins/tmux-sensible' +set -g @plugin 'dreamsofcode-io/catppuccin-tmux' + +run '~/.tmux/plugins/tpm/tpm' + +if "test ! -d ~/.tmux/plugins/tpm" \ + "run 'git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && ~/.tmux/plugins/tpm/bin/install_plugins'" +EOT +fi + +gem install bundler +NUM_CORES=$( cat /proc/cpuinfo | grep '^processor'|wc -l ) +bundle config --global jobs `expr $NUM_CORES - 1` + +# Update test DB config +echo 'test_database_url: postgis://postgres:password@localhost:5432/vets_api_test?pool=4' > config/settings/test.local.yml + +# Add service config +if [ ! -f config/settings.local.yml ]; then + cp config/settings.local.yml.example config/settings.local.yml + cat <> config/settings.local.yml +database_url: postgis://postgres:password@localhost:5432/vets_api_development?pool=4 +test_database_url: postgis://postgres:password@localhost:5432/vets_api_test?pool=4 + +redis: + host: localhost + port: 6379 + app_data: + url: redis://localhost:6379 + sidekiq: + url: redis://localhost:6379 + +betamocks: + cache_dir: ../vets-api-mockdata + +# Allow access from localhost and shared github URLs. +virtual_hosts: ["127.0.0.1", "localhost", !ruby/regexp /.*\.app\.github\.dev/] +EOT +fi + +mkdir -p log +nohup bash -c '/home/linuxbrew/.linuxbrew/opt/redis@6.2/bin/redis-server /home/linuxbrew/.linuxbrew/etc/redis.conf' >> log/redis.log 2>&1 & +sudo /etc/init.d/postgresql restart +pg_isready -t 60 +sudo -u root sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'password';" +./bin/setup diff --git a/.devcontainer/neovim-tmux-zsh/post-start.sh b/.devcontainer/neovim-tmux-zsh/post-start.sh new file mode 100644 index 00000000000..0abf46ab86d --- /dev/null +++ b/.devcontainer/neovim-tmux-zsh/post-start.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +echo "Starting redis..." +nohup /home/linuxbrew/.linuxbrew/opt/redis@6.2/bin/redis-server /home/linuxbrew/.linuxbrew/etc/redis.conf >> log/redis.log 2>&1 & + +echo "Starting postgres..." +sudo /etc/init.d/postgresql restart +echo "Waiting for postgres to be ready..." +pg_isready -t 60 diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index 20bb30340b8..b01f08ae3ab 100644 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -13,20 +13,6 @@ git clone https://github.com/department-of-veterans-affairs/vets-api-mockdata.gi sudo apt update sudo apt install -y libpq-dev pdftk shared-mime-info postgresql-15-postgis-3 -# Add tmux config -if [ ! -f $HOME/.tmux.conf ]; then - cat <> $HOME/.tmux.conf -set -g @plugin 'tmux-plugins/tpm' -set -g @plugin 'tmux-plugins/tmux-sensible' -set -g @plugin 'dreamsofcode-io/catppuccin-tmux' - -run '~/.tmux/plugins/tpm/tpm' - -if "test ! -d ~/.tmux/plugins/tpm" \ - "run 'git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && ~/.tmux/plugins/tpm/bin/install_plugins'" -EOT -fi - gem install bundler NUM_CORES=$( cat /proc/cpuinfo | grep '^processor'|wc -l ) bundle config --global jobs `expr $NUM_CORES - 1`