Skip to content

Fine Grained access rights #1310

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 182 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
182 commits
Select commit Hold shift + click to select a range
7ff9df3
SaveAsTemplate moved away from StudyDetailsEditor
odeimaiz Feb 24, 2020
bc90aa5
dummy ShareWith widget added
odeimaiz Feb 24, 2020
42e0cbc
added dummy Organizations
odeimaiz Feb 25, 2020
ea1e09b
getActiveMenuButtons added
odeimaiz Feb 25, 2020
266e4ae
1st share with organization version
odeimaiz Feb 25, 2020
0846b79
minor
odeimaiz Feb 25, 2020
7044dee
Merge branch 'master' into feature/user-access-rights
odeimaiz Mar 31, 2020
3ab6294
Merge branch 'master' into feature/user-access-rights
odeimaiz Apr 2, 2020
33ad815
Merge branch 'master' into feature/user-access-rights
odeimaiz Apr 6, 2020
afb9db9
Fixes #1437
odeimaiz Apr 7, 2020
0a4482f
Delete studies one by one and show error if fails. Fixes #1344
odeimaiz Apr 7, 2020
ed1d82b
Minor
odeimaiz Apr 7, 2020
8b0e781
groupId -> dagId
odeimaiz Apr 7, 2020
12a7cea
orgId -> shareContextId
odeimaiz Apr 7, 2020
8960a6d
orgId -> shareGroupId
odeimaiz Apr 7, 2020
e92162b
refactoring
odeimaiz Apr 7, 2020
9d1fbc1
minor fix
odeimaiz Apr 7, 2020
5aceb6e
minor
odeimaiz Apr 7, 2020
6aa5379
minor
odeimaiz Apr 7, 2020
6acc231
added ShareWith widget to export group
odeimaiz Apr 7, 2020
47a369a
minor
odeimaiz Apr 7, 2020
018fbfd
Merge branch 'master' into feature/user-access-rights
odeimaiz Apr 7, 2020
d0a7f3d
Merge branch 'master' into feature/user-access-rights
odeimaiz Apr 8, 2020
2f5706a
minor
odeimaiz Apr 8, 2020
4418e7a
groupId -> filterGroupId
odeimaiz Apr 8, 2020
16be66e
shareGroupId -> GID
odeimaiz Apr 8, 2020
c12e7d8
minor
odeimaiz Apr 8, 2020
837f40b
Api scecs support accessRights and organizations
odeimaiz Apr 8, 2020
a8e4a4b
List organizations in profile page
odeimaiz Apr 8, 2020
a4123b0
List organizations and wait for Promises
odeimaiz Apr 9, 2020
7f0811c
aesthetics
odeimaiz Apr 9, 2020
9f1ab2c
Show saharing icon in study card
odeimaiz Apr 9, 2020
7788672
minor
odeimaiz Apr 9, 2020
4efdeae
Merge branch 'master' into feature/user-access-rights
odeimaiz Apr 14, 2020
02b9f06
Merge branch 'feature/user-access-rights' of github.com:odeimaiz/ospa…
odeimaiz Apr 14, 2020
ceeeb85
using osparc hint
odeimaiz Apr 14, 2020
cfa030a
minor
odeimaiz Apr 14, 2020
188ea8a
minor
odeimaiz Apr 14, 2020
bbb9ff5
minor
odeimaiz Apr 14, 2020
7369dfe
fit icon in StudyBrowserButtonItem
odeimaiz Apr 14, 2020
e26c622
minor fix
odeimaiz Apr 14, 2020
35c3486
Using same GroupIDs in dummy Organizations and AccessRight
odeimaiz Apr 14, 2020
304cf9a
Markdown's noMargin true by default
odeimaiz Apr 14, 2020
4a5ff94
do not serialize accessRights
odeimaiz Apr 14, 2020
a2af0cb
minor
odeimaiz Apr 14, 2020
640fef8
"title-14" or "text-14" for navigationBar
odeimaiz Apr 14, 2020
bcad75f
text uniformity
odeimaiz Apr 14, 2020
c74ea51
smaller texts
odeimaiz Apr 14, 2020
e44c0fe
minor
odeimaiz Apr 14, 2020
d286209
sideCollapsed is not used
odeimaiz Apr 14, 2020
b4d4db7
minor
odeimaiz Apr 14, 2020
b99b99e
PanelView splitted into CollapsibleView and PanelView
odeimaiz Apr 15, 2020
9fb71df
Templates and studies are collapsible
odeimaiz Apr 15, 2020
33b30b0
more uniform fonts
odeimaiz Apr 15, 2020
abefca3
more text uniformity
odeimaiz Apr 16, 2020
a2bca30
me endpoint gives more info + renaming
odeimaiz Apr 16, 2020
879b7c7
minor fix
odeimaiz Apr 16, 2020
3ffd74b
more examples
odeimaiz Apr 16, 2020
9e669c7
minor
odeimaiz Apr 16, 2020
6409923
minor fix
odeimaiz Apr 16, 2020
043fe0e
staying iframe bug fixed (@sanderegg )
odeimaiz Apr 17, 2020
99758ff
Merge branch 'master' into feature/user-access-rights
sanderegg Apr 20, 2020
14b2418
add json plugin in adminer
sanderegg Apr 20, 2020
6ada7c0
up-devel can update the stack
sanderegg Apr 20, 2020
d47d03f
change adminer theme
sanderegg Apr 20, 2020
b0e9097
added groups model
sanderegg Apr 20, 2020
8accd58
updated schemas
sanderegg Apr 20, 2020
a69b109
typo
sanderegg Apr 20, 2020
427a7de
use debian base
sanderegg Apr 20, 2020
0898393
added groups and user_to_groups tables
sanderegg Apr 20, 2020
5e5d585
add description of group
sanderegg Apr 20, 2020
5cea4f7
set default log to warning
sanderegg Apr 20, 2020
229ede4
[email protected] -> [email protected]
odeimaiz Apr 22, 2020
fa4b041
Merge branch 'feature/user-access-rights' of github.com:odeimaiz/ospa…
odeimaiz Apr 22, 2020
26ef5ed
auto update modified field using server side time
sanderegg Apr 22, 2020
5e7d895
add user primary group
sanderegg Apr 22, 2020
412f180
added migration scripts for groups and user triggers
sanderegg Apr 22, 2020
66022e6
added test own group constraints
sanderegg Apr 22, 2020
bd89190
Merge branch 'feature/user-access-rights' of https://github.com/odeim…
sanderegg Apr 22, 2020
4334687
return my group
sanderegg Apr 22, 2020
366f88c
me handler returns my group and the others me is in
sanderegg Apr 22, 2020
0701cde
Merge branch 'master' into feature/user-access-rights
odeimaiz Apr 23, 2020
39e3df3
fix altering column default
sanderegg Apr 24, 2020
e0db256
create migration for changing project prj_owner
sanderegg Apr 24, 2020
b6e39a1
pass access rights with project on creation
sanderegg Apr 27, 2020
d7ec0b0
add access right column
sanderegg Apr 27, 2020
e9acda3
Merge branch 'master' into odeimaiz-feature/user-access-rights
sanderegg Apr 29, 2020
6f43af5
Merge branch 'master' into feature/user-access-rights
odeimaiz Apr 29, 2020
f437404
fixed creation of project
sanderegg Apr 29, 2020
af3ea4d
enable accessrights
sanderegg Apr 29, 2020
64a31c8
minor
odeimaiz Apr 29, 2020
d56ca29
filter projects based on bad idea
sanderegg Apr 29, 2020
0d1c8b4
access rights column is a JSONB to allow search inside JSON
sanderegg Apr 29, 2020
5761a96
get a direct way of filtering in templates
sanderegg Apr 29, 2020
2df12e0
merge fix
sanderegg May 1, 2020
624b56f
fix import issue
sanderegg May 1, 2020
928ff34
added group type
sanderegg May 1, 2020
67c330b
added everyone group
sanderegg May 1, 2020
b47f8d9
typo
sanderegg May 1, 2020
5cd6b39
added read-only of group Everyone
sanderegg May 1, 2020
8a5552d
fixed postgres package tests on groups
sanderegg May 1, 2020
e1f0e1a
clean up
sanderegg May 1, 2020
5e0f203
load template with access rights or as project owner
sanderegg May 3, 2020
169d58f
return the all group when getting profile
sanderegg May 3, 2020
da55756
removed call to get email
sanderegg May 3, 2020
a2bbc63
test conversion of prj_owner to string
sanderegg May 3, 2020
1e571f3
updated projects with accessRights property
sanderegg May 3, 2020
e78da66
prj_owner can be null
sanderegg May 3, 2020
99e1fee
fix typo in test??
sanderegg May 3, 2020
9fce85d
prjOwner is now the user id as string
sanderegg May 3, 2020
e9d6402
prjOwner is a string
sanderegg May 4, 2020
6c88a92
when the uuid is not one it is re-created
sanderegg May 4, 2020
fafc335
cleanup
sanderegg May 4, 2020
af9d5d8
using fixed all group gid
sanderegg May 4, 2020
e531b38
Merge pull request #63 from sanderegg/odeimaiz-feature/user-access-ri…
odeimaiz May 4, 2020
dee5b30
Merge branch 'master' into feature/user-access-rights
odeimaiz May 4, 2020
b05dadc
minor
odeimaiz May 4, 2020
e1b1963
eslint
odeimaiz May 4, 2020
181f369
__isUserOwner returns true
odeimaiz May 4, 2020
97f358f
Permissions update: "user"s can create templates
odeimaiz May 4, 2020
b09a9e0
removed hardcoded groups
odeimaiz May 4, 2020
fb56295
refactoring
odeimaiz May 4, 2020
71c21aa
backend supports accessRights
odeimaiz May 4, 2020
3a2f55f
minor
odeimaiz May 4, 2020
30b9628
adds user_api
sanderegg May 4, 2020
f4e1ff0
fixed test projects
sanderegg May 4, 2020
00a0b55
missing tables for testing
sanderegg May 4, 2020
f982bb0
hardcoding out
odeimaiz May 4, 2020
52ca28b
GID -> gid
odeimaiz May 4, 2020
e14d186
guest has a prjOwner unknown for now
sanderegg May 4, 2020
81d2652
in case a valid uuid is not passed check that it gets generated
sanderegg May 4, 2020
6a29b28
linter
sanderegg May 4, 2020
68080e2
updated test of /me
sanderegg May 4, 2020
9b5c563
linter
sanderegg May 4, 2020
f786b25
updated project jsonschema in storage
sanderegg May 4, 2020
b3d32f3
updated project jsonschema in director
sanderegg May 4, 2020
30120d9
add groups and user_to_groups table for storage testing
sanderegg May 4, 2020
8f4fba5
fix sleepers template
sanderegg May 4, 2020
0e47cde
missing accessRights entry
sanderegg May 4, 2020
537a4c7
linter
sanderegg May 4, 2020
de7d2d3
fixes tests in storage
sanderegg May 4, 2020
f88cb90
write accessRight when creating template
odeimaiz May 4, 2020
c54a1d4
Working fine!
odeimaiz May 4, 2020
50c6541
script to copy any docker volume out of a distant host
sanderegg May 4, 2020
c016851
create a production ready database to test migration on
sanderegg May 4, 2020
ea35e81
add setup-prod recipe
sanderegg May 4, 2020
e7e71f9
added calls to import a docker volume for testing database migration
sanderegg May 4, 2020
2287bd0
minor
odeimaiz May 4, 2020
ff41481
renaming
odeimaiz May 4, 2020
597a1a2
use guards to check on env variables
sanderegg May 4, 2020
cbdec8b
migration of current users to get their primary group
sanderegg May 4, 2020
460bd97
migrate template projects access rights
sanderegg May 4, 2020
ea0d356
Merge branch 'feature/user-access-rights' of https://github.com/odeim…
sanderegg May 4, 2020
650518b
fix pytest warning
sanderegg May 4, 2020
8c3fc50
linter
sanderegg May 5, 2020
c52da0d
api transmits prjOwner as email again. in DB still the user id
sanderegg May 5, 2020
61ac4a2
Revert "renaming"
odeimaiz May 5, 2020
470c9fc
shared with icons
odeimaiz May 5, 2020
2610a2a
get all groups at once
odeimaiz May 5, 2020
4df4c7b
Merge pull request #64 from sanderegg/odeimaiz-feature/user-access-ri…
odeimaiz May 5, 2020
df6e870
fix tutorial project
sanderegg May 5, 2020
0d5b561
minor
odeimaiz May 5, 2020
0a2cb9d
renaming
odeimaiz May 5, 2020
ee6d496
more renaming + cleanup
odeimaiz May 5, 2020
83212ae
minor
odeimaiz May 5, 2020
9694c0e
disable ShareWith part in ExportDAG
odeimaiz May 5, 2020
d06f8dc
ExportGroup -> ExportDAG
odeimaiz May 5, 2020
e4b3e7a
fix e2e testing missing empty string thumbnail
sanderegg May 5, 2020
5d8a869
provide adequate e-mail
sanderegg May 5, 2020
f23f094
reset AccessRights when instantiating a template
odeimaiz May 5, 2020
f9041fe
allow users delete their templates
odeimaiz May 5, 2020
4d4075e
Merge pull request #65 from sanderegg/odeimaiz-feature/user-access-ri…
odeimaiz May 5, 2020
71f6908
dynamic exportButton. closes #1486
odeimaiz May 5, 2020
3c6caf8
typo
sanderegg May 5, 2020
1af1ecc
typo (thanks @sanderegg)
odeimaiz May 5, 2020
90b82fd
fixes create as template not changing the project file paths
sanderegg May 5, 2020
0537c0b
Merge pull request #67 from sanderegg/odeimaiz-feature/user-access-ri…
odeimaiz May 5, 2020
deded51
make eslint happy
odeimaiz May 5, 2020
2b1216f
Merge branch 'master' into feature/user-access-rights
sanderegg May 5, 2020
f56058f
@pcrespov review
sanderegg May 6, 2020
13acf87
Merge pull request #68 from sanderegg/odeimaiz-feature/user-access-ri…
odeimaiz May 6, 2020
d94c927
Merge branch 'master' into feature/user-access-rights
sanderegg May 6, 2020
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ endif


up-devel: .stack-simcore-development.yml .init-swarm $(CLIENT_WEB_OUTPUT) ## Deploys local development stack, qx-compile+watch and ops stack (pass 'make ops_disabled=1 up-...' to disable)
# Start compile+watch front-end container [front-end]
$(MAKE_C) services/web/client compile-dev flags=--watch
# Start compile+watch front-end container [front-end]
$(MAKE_C) services/web/client down compile-dev flags=--watch
# Deploy stack $(SWARM_STACK_NAME) [back-end]
@docker stack deploy -c $< $(SWARM_STACK_NAME)
$(MAKE) .deploy-ops
Expand Down
9 changes: 8 additions & 1 deletion api/specs/common/schemas/project-v0.0.1-converted.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ required:
- name
- description
- prjOwner
- accessRights
- creationDate
- lastChangeDate
- thumbnail
Expand All @@ -26,7 +27,13 @@ properties:
example: Dabbling in temporal transitions ...
prjOwner:
type: string
description: user uuid
format: idn-email
description: user email
accessRights:
type: object
description: >-
object containing the GroupID as key and read/write/execution permissions
as value
creationDate:
type: string
description: project creation date
Expand Down
33 changes: 26 additions & 7 deletions api/specs/common/schemas/project-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"name",
"description",
"prjOwner",
"accessRights",
"creationDate",
"lastChangeDate",
"thumbnail",
Expand Down Expand Up @@ -40,7 +41,12 @@
},
"prjOwner": {
"type": "string",
"description": "user uuid"
"format": "idn-email",
"description": "user email"
},
"accessRights": {
"type": "object",
"description": "object containing the GroupID as key and read/write/execution permissions as value"
},
"creationDate": {
"type": "string",
Expand Down Expand Up @@ -101,7 +107,7 @@
"type": "string"
},
"progress": {
"type":"number",
"type": "number",
"maximum": 100,
"minimum": 0,
"description": "the node progress value"
Expand Down Expand Up @@ -153,7 +159,10 @@
],
"properties": {
"store": {
"type": ["string", "integer"]
"type": [
"string",
"integer"
]
},
"dataset": {
"type": "string"
Expand All @@ -176,7 +185,11 @@
"patternProperties": {
"^[-_a-zA-Z0-9]+$": {
"type": "string",
"enum": ["Invisible", "ReadOnly", "ReadAndWrite"],
"enum": [
"Invisible",
"ReadOnly",
"ReadAndWrite"
],
"default": "ReadAndWrite",
"examples": [
"ReadOnly"
Expand Down Expand Up @@ -219,7 +232,10 @@
],
"properties": {
"store": {
"type": ["string", "integer"]
"type": [
"string",
"integer"
]
},
"dataset": {
"type": "string"
Expand Down Expand Up @@ -253,7 +269,10 @@
]
},
"parent": {
"type": ["string", "null"],
"type": [
"string",
"null"
],
"pattern": "^\\S+$",
"description": "Parent's (group-nodes') node ID s.",
"examples": [
Expand Down Expand Up @@ -288,4 +307,4 @@
}
}
}
}
}
31 changes: 31 additions & 0 deletions api/specs/webserver/components/schemas/me.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ ProfileOutput:
format: email
role:
type: string
groups:
type: object
properties:
me:
$ref: '#/UsersGroup'
organizations:
type: array
items:
$ref: '#/UsersGroup'
all:
$ref: '#/UsersGroup'
gravatar_id:
type: string
example:
Expand All @@ -48,6 +59,26 @@ ProfileEnveloped:
default: null


UsersGroup:
type: object
properties:
gid:
type: string
label:
type: string
description:
type: string
example:
- gid: '27'
label: 'A user'
description: 'A very special user'
- gid: '1'
label: 'ITIS Foundation'
description: 'The Foundation for Research on Information Technologies in Society'
- gid: '0'
label: 'All'
description: 'Open to all users'

Token:
description: api keys for third party services
type: object
Expand Down
21 changes: 14 additions & 7 deletions api/tests/test_repo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from utils import current_repo_dir

SYNCED_VERSIONS_SUFFIX = [
".json", # json-schema specs file
"-converted.yaml" # equivalent openapi specs file (see scripts/json-schema-to-openapi-schema)
".json", # json-schema specs file
"-converted.yaml", # equivalent openapi specs file (see scripts/json-schema-to-openapi-schema)
]


Expand All @@ -38,29 +38,33 @@
# ./tests/integration/computation/workbench_sleeper_dag_adjacency_list.json
# ./tests/integration/computation/workbench_sleeper_payload.json


def _load_data(fpath: Path):
with open(fpath) as fh:
try:
data = json.load(fh)
except json.JSONDecodeError:
fh.seek(0)
data = yaml.load(fh)
data = yaml.safe_load(fh)
return data


@pytest.fixture(
scope="module",
params= [ str(schema_path)
params=[
str(schema_path)
for suffix in SYNCED_VERSIONS_SUFFIX
for schema_path in current_repo_dir.rglob(f"schemas/project*{suffix}")
]
],
)
def project_schema(request, api_specs_dir):
schema_path = Path(request.param)
return _load_data(schema_path)


# TESTS --------------------------------------------------


@pytest.mark.parametrize("data_path", PROJECTS_PATHS)
def test_project_against_schema(data_path, project_schema, this_repo_root_dir):
"""
Expand All @@ -80,13 +84,16 @@ def test_project_against_schema(data_path, project_schema, this_repo_root_dir):
"creationDate": "8715-11-30T9:1:51.388Z",
"lastChangeDate": "0944-02-31T5:1:7.795Z",
"thumbnail": "labore incid",
"workbench": data["workbench"]
"accessRights": {},
"workbench": data["workbench"],
}
data = prj

assert any(isinstance(data, _type) for _type in [List, Dict])
if isinstance(data, Dict):
data = [data,]
data = [
data,
]

for project_data in data:
jsonschema.validate(project_data, project_schema)
30 changes: 24 additions & 6 deletions packages/postgres-database/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ tests: ## runs unit tests
@pytest -vv --exitfirst --failed-first --durations=10 --pdb $(CURDIR)/tests


.PHONY: import-db
import-db: scripts/copy_database_volume.sh guard-SOURCE_HOST guard-SOURCE_DATA_VOLUME guard-TARGET_DATA_VOLUME ## copy volume $(SOURCE_DATA_VOLUME) from $(SOURCE_HOST) into local $(TARGET_DATA_VOLUME)
./scripts/copy_database_volume.sh

guard-%:
@ if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
exit 1; \
fi

.PHONY: setup-prod
export POSTGRES_DATA_VOLUME = $(TARGET_DATA_VOLUME)
setup-prod: install-dev up-prod ## sets up a database using an external postgres volume to test migration
# discovering
sc-pg --help
@echo "To test migration, sc-pg discover -u USER -p PASSWORD, then sc-pg upgrade"

.PHONY: setup-commit
setup-commit: install-dev up-pg ## sets up a database to create a new commit into migration history
# discovering
Expand All @@ -46,11 +63,12 @@ migrate: $(DOT_ENV_FILE) ## basic migration update (use ONLY for development pur



.PHONY: up-pg down-pg
DOCKER_COMPOSE_CONFIG := tests/docker-compose.yml
.PHONY: up-pg down-pg up-prod down-prod
docker-compose-configs = $(wildcard tests/docker-compose*.yml)
up-pg up-prod: $(docker-compose-configs) ## starts pg server
docker-compose -f tests/docker-compose.yml $(if $(findstring -prod,$@),-f tests/docker-compose.prod.yml,) up -d

down-pg down-prod: $(docker-compose-configs) ## stops pg server
docker-compose -f tests/docker-compose.yml $(if $(findstring -prod,$@),-f tests/docker-compose.prod.yml,) down

up-pg: $(DOCKER_COMPOSE_CONFIG) ## starts pg server
docker-compose -f $< up -d

down-pg: $(DOCKER_COMPOSE_CONFIG) ## stops pg server
docker-compose -f $< down
61 changes: 42 additions & 19 deletions packages/postgres-database/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,54 @@
FROM python:3.6-alpine
FROM python:3.6-slim as base

LABEL maintainer=sanderegg

# Sets utf-8 encoding for Python et al
ENV LANG=C.UTF-8
# Turns off writing .pyc files; superfluous on an ephemeral container.
ENV PYTHONDONTWRITEBYTECODE=1 \
VIRTUAL_ENV=/home/scu/.venv
# Ensures that the python and pip executables used
# in the image will be those from our virtualenv.
ENV PATH="${VIRTUAL_ENV}/bin:$PATH"


FROM base as build

RUN apt-get update &&\
apt-get install -y --no-install-recommends \
build-essential \
git

# NOTE: python virtualenv is used here such that installed packages may be moved to production image easily by copying the venv
RUN python -m venv ${VIRTUAL_ENV}

RUN pip --no-cache-dir install --upgrade \
pip~=20.0.2 \
wheel \
setuptools

ARG GIT_BRANCH
ARG GIT_REPOSITORY

RUN apk add --no-cache --virtual .build-deps \
gcc \
git \
python3-dev \
musl-dev \
postgresql-dev \
&& git clone --single-branch --branch ${GIT_BRANCH} ${GIT_REPOSITORY} \
&& pip install osparc-simcore/packages/postgres-database[migration] \
&& apk del --no-cache .build-deps

# runtime dependency
RUN apk add --no-cache \
bash \
postgresql
RUN git clone --single-branch --branch ${GIT_BRANCH} ${GIT_REPOSITORY} \
&& pip install osparc-simcore/packages/postgres-database[migration]

FROM base as production

ENV PYTHONOPTIMIZE=TRUE

WORKDIR /home/scu

# bring installed package without build tools
COPY --from=build ${VIRTUAL_ENV} ${VIRTUAL_ENV}
COPY entrypoint.bash /home/entrypoint.bash


ENV POSTGRES_USER=scu \
POSTGRES_PASSWORD=adminadmin \
POSTGRES_HOST=postgres \
POSTGRES_PORT=5432 \
POSTGRES_DB=simcoredb
POSTGRES_PASSWORD=adminadmin \
POSTGRES_HOST=postgres \
POSTGRES_PORT=5432 \
POSTGRES_DB=simcoredb

ENTRYPOINT [ "/bin/sh", "/home/entrypoint.bash" ]
CMD [ "sc-pg", "upgrade" ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE OR REPLACE FUNCTION upgrade_user_table_with_groups() RETURNS VOID AS $$
DECLARE
group_id BIGINT;
temprow RECORD;
BEGIN
FOR temprow IN SELECT id, name FROM "users" WHERE "primary_gid" IS NULL
LOOP
INSERT INTO "groups" ("name", "description") VALUES (temprow.name, 'primary group') RETURNING gid INTO group_id;
INSERT INTO "user_to_groups" ("uid", "gid") VALUES (temprow.id, group_id);
UPDATE "users" SET "primary_gid" = group_id WHERE "id" = temprow.id;
END LOOP;
END; $$ LANGUAGE 'plpgsql';

SELECT upgrade_user_table_with_groups()
DROP FUNCTION upgrade_user_table_with_groups()
10 changes: 10 additions & 0 deletions packages/postgres-database/scripts/copy_database_volume.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
set -o errexit
set -o nounset

IFS=$(printf '\n\t')

ssh "${SOURCE_HOST}" \
"docker run --rm -v ${SOURCE_DATA_VOLUME}:/from alpine ash -c 'cd /from ; tar -cf - . '" \
| \
docker run --rm -i -v "${TARGET_DATA_VOLUME}":/to alpine ash -c "cd /to ; tar -xpvf - "
Loading