make devcontainer experience a bit nicer with npm autoinstall and one less db

This commit is contained in:
2023-01-14 23:24:23 +00:00
committed by Stepan Usatiuk
parent 101e2ceed7
commit 09844e5294
6 changed files with 45 additions and 83 deletions

View File

@@ -1,20 +1,5 @@
# Update the VARIANT arg in docker-compose.yml to pick a Node version: 10, 12, 14
ARG VARIANT="16-buster"
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}
ENV DOCKERDEV=true
# Update args in docker-compose.yaml to set the UID/GID of the "node" user.
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \
groupmod --gid $USER_GID node \
&& usermod --uid $USER_UID --gid $USER_GID node \
&& chmod -R $USER_UID:$USER_GID /home/node \
&& chmod -R $USER_UID:root /usr/local/share/nvm /usr/local/share/npm-global; \
fi
RUN sudo -u node npm config set unsafe-perm=true
ARG VARIANT=16-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
@@ -24,6 +9,5 @@ RUN sudo -u node npm config set unsafe-perm=true
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
# [Optional] Uncomment if you want to install more global node packages
# RUN sudo -u node npm install -g <your-package-list-here>
# [Optional] Uncomment if you want to install more global node modules
# RUN su node -c "npm install -g <your-package-list-here>"

5
.devcontainer/dbinit/fix.sql Executable file
View File

@@ -0,0 +1,5 @@
FLUSH PRIVILEGES ;
DROP USER ''@'localhost' ;
create database if not exists `photostestdb` ;
grant all privileges on `photostestdb`.* to 'photostestuser'@'%' identified by 'photostestpass' ;
FLUSH PRIVILEGES ;

View File

@@ -9,12 +9,18 @@
// Set *default* container specific settings.json values on container create.
"settings": {},
// Add the IDs of extensions you want installed when the container is created.
"extensions": ["dbaeumer.vscode-eslint"],
"extensions": [
"dbaeumer.vscode-eslint",
"mikestead.dotenv",
"esbenp.prettier-vscode",
"foxundermoon.shell-format",
"ms-azuretools.vscode-docker"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [1234, 3000],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "npm config set unsafe-perm=true && npm i && cd frontend && npm i",
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node",
"postCreateCommand": "cd /workspace; if [ ! -f ormconfig.json ]; then cp ormconfig.dockerdevexample.json ormconfig.json; fi; if [ ! -f ormconfig.test.json ]; then cp ormconfig.dockerdevexample.test.json ormconfig.test.json; fi;"
"postCreateCommand": "cd /workspace; if [ ! -f ormconfig.json ]; then cp ormconfig.dockerdevexample.json ormconfig.json; fi; if [ ! -f ormconfig.test.json ]; then cp ormconfig.dockerdevexample.test.json ormconfig.test.json; fi; npm i && cd frontend && npm i"
}

View File

@@ -5,13 +5,6 @@ services:
build:
context: .
dockerfile: Dockerfile
args:
# [Choice] Node.js version: 14, 12, 10
VARIANT: 16
# On Linux, you may need to update USER_UID and USER_GID below if not your local UID is not 1000.
USER_UID: 1000
USER_GID: 1000
volumes:
- ..:/workspace:cached
@@ -21,35 +14,21 @@ services:
# 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: node
# 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: mariadb:latest
image: yobasystems/alpine-mariadb:10.6
volumes:
- photosmariadb-data:/var/lib/mysql
- ./dbinit:/docker-entrypoint-initdb.d:ro
environment:
MYSQL_DATABASE: photos
MYSQL_USER: photos
MYSQL_PASSWORD: photos
MYSQL_ROOT_PASSWORD: photos
dbtest:
image: mariadb:latest
volumes:
- photosmariadbtest-data:/var/lib/mysql
environment:
MYSQL_DATABASE: photos_test
MYSQL_USER: photos
MYSQL_PASSWORD: photos
MYSQL_ROOT_PASSWORD: photos
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward MongoDB locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
MYSQL_DATABASE: photosdb
MYSQL_USER: photosuser
MYSQL_PASSWORD: photospass
MYSQL_ROOT_PASSWORD: photosroot
healthcheck:
test: "mysql $$MYSQL_DATABASE -u$$MYSQL_USER -p$$MYSQL_PASSWORD -e 'SELECT 1;'"
interval: 10s
timeout: 10s
retries: 10
volumes:
photosmariadb-data:
photosmariadbtest-data:

View File

@@ -2,20 +2,14 @@
"type": "mariadb",
"host": "db",
"port": 3306,
"username": "photos",
"password": "photos",
"database": "photos",
"username": "photosuser",
"password": "photospass",
"database": "photosdb",
"synchronize": false,
"logging": false,
"entities": [
"src/entity/**/*.ts"
],
"migrations": [
"src/migration/**/*.ts"
],
"subscribers": [
"src/subscriber/**/*.ts"
],
"entities": ["src/entity/**/*.ts"],
"migrations": ["src/migration/**/*.ts"],
"subscribers": ["src/subscriber/**/*.ts"],
"cli": {
"entitiesDir": "src/entity",
"migrationsDir": "src/migration",

View File

@@ -1,21 +1,15 @@
{
"type": "mariadb",
"host": "dbtest",
"host": "db",
"port": 3306,
"username": "photos",
"password": "photos",
"database": "photos_test",
"username": "photostestuser",
"password": "photostestpass",
"database": "photostestdb",
"synchronize": true,
"logging": false,
"entities": [
"src/entity/**/*.ts"
],
"migrations": [
"src/migration/**/*.ts"
],
"subscribers": [
"src/subscriber/**/*.ts"
],
"entities": ["src/entity/**/*.ts"],
"migrations": ["src/migration/**/*.ts"],
"subscribers": ["src/subscriber/**/*.ts"],
"cli": {
"entitiesDir": "src/entity",
"migrationsDir": "src/migration",