Skip to content

Commit

Permalink
CHG adjust environment for running in anubis ide
Browse files Browse the repository at this point in the history
  • Loading branch information
wabscale committed Sep 20, 2022
1 parent 1a83e60 commit 1953555
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 39 deletions.
29 changes: 16 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
DEBUG_PERSISTENT_SERVICES := db traefik redis-master
DEBUG_RESTART_ALWAYS_SERVICES := api web-dev rpc-default rpc-theia rpc-regrade

# docker-compose settings
# docker compose settings
DOCKER_COMPOSE_PUSH_SERVICES := api web theia-init theia-sidecar theia-proxy theia-dockerd

# K8S
Expand All @@ -14,6 +14,9 @@ K8S_RESTART_DEPLOYMENTS := \
GIT_TAG ?= $(shell git log -1 --pretty=%h)
export GIT_TAG

TRAEFIK_PORT := $(shell if [ "$$ANUBIS_IDE" = "1" ]; then echo 8000; else echo 80; fi)
ANUBIS_UID := $(shell if [ "$$ANUBIS_IDE" = "1" ]; then echo 1001; else echo 1000; fi)

help:
@echo 'For convenience'
@echo
Expand Down Expand Up @@ -52,24 +55,24 @@ status:

.PHONY: build # Build all docker images
build:
docker-compose build --parallel --pull $(DOCKER_COMPOSE_PUSH_SERVICES)
env GIT_TAG=latest docker-compose build --parallel --pull $(DOCKER_COMPOSE_PUSH_SERVICES)
docker compose build --parallel --pull $(DOCKER_COMPOSE_PUSH_SERVICES)
env GIT_TAG=latest docker compose build --parallel --pull $(DOCKER_COMPOSE_PUSH_SERVICES)

.PHONY: push # Push images to registry.digitalocean.com (requires vpn)
push: build
docker-compose push $(DOCKER_COMPOSE_PUSH_SERVICES)
env GIT_TAG=latest docker-compose push $(DOCKER_COMPOSE_PUSH_SERVICES)
docker compose push $(DOCKER_COMPOSE_PUSH_SERVICES)
env GIT_TAG=latest docker compose push $(DOCKER_COMPOSE_PUSH_SERVICES)

.PHONY: debug # Start the cluster in debug mode
debug:
docker-compose up -d $(DEBUG_PERSISTENT_SERVICES)
docker-compose up \
docker compose up -d $(DEBUG_PERSISTENT_SERVICES)
docker compose up \
-d --force-recreate \
$(DEBUG_RESTART_ALWAYS_SERVICES)
@echo 'Waiting for db'
@until mysqladmin -h 127.0.0.1 ping &> /dev/null; do sleep 1; done
@echo 'running migrations'
docker-compose exec api alembic upgrade head
docker compose exec api alembic upgrade head
make startup-links

.PHONY: mindebug # Setup mindebug environment
Expand Down Expand Up @@ -97,13 +100,13 @@ apirun:
webrun:
make -C web run

# Reset local docker-compose db
# Reset local docker compose db
yeetdb:
docker-compose kill db
docker-compose rm -f
docker compose kill db
docker compose rm -f
docker volume rm anubis_db_data
docker-compose up -d --force-recreate db
docker compose up -d --force-recreate db

theia-%:
docker-compose build $@
docker compose build $@

20 changes: 10 additions & 10 deletions api/anubis/k8s/theia.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ def create_theia_k8s_pod_pvc(
theia_extra_env.append(anubis_assignment_tests_repo_env)
sidecar_extra_env.append(anubis_assignment_tests_repo_env)

# Initialize theia volume mounts array with
# the project volume mount
theia_volume_mounts.append(
k8s.V1VolumeMount(
mount_path="/home/anubis",
name=theia_volume_name,
)
)

##################################################################################
# INIT CONTAINER

Expand Down Expand Up @@ -314,7 +323,7 @@ def create_theia_k8s_pod_pvc(
),
# Add the shared certs volume
volume_mounts=[
certs_volume_mount
*theia_volume_mounts,
],
)

Expand Down Expand Up @@ -377,15 +386,6 @@ def create_theia_k8s_pod_pvc(
if webtop:
theia_user_id = 0

# Initialize theia volume mounts array with
# the project volume mount
theia_volume_mounts.append(
k8s.V1VolumeMount(
mount_path="/home/anubis",
name=theia_volume_name,
)
)

# If privileged, add docker config file to pod as a volume
if admin and include_docker_secret:
pod_volumes.append(
Expand Down
2 changes: 1 addition & 1 deletion api/tests/test_ide_k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _check_assignment_ide(_ide_id):
assert ide.autosave is True
assert ide.playground is False
assert ide.admin is False
assert ide.privileged is False
assert ide.docker is False
assert ide.persistent_storage is False
assert ide.repo_url == 'https://github.com/AnubisLMS/xv6'

Expand Down
10 changes: 2 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ services:
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.http.address=:80"
- "--entrypoints.https.address=:443"

ports:
- "80:80"
- "443:443"
- "${TRAEFIK_PORT:-80}:80"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
labels:
Expand Down Expand Up @@ -55,8 +53,6 @@ services:
- "GITHUB_TOKEN"
- "SENTRY_DSN"
- "CREATE_APP_FUNCTION=create_pipeline_app"
ports:
- 127.0.0.1:5004:5004
volumes:
- "./api:/opt/app"
labels:
Expand Down Expand Up @@ -107,16 +103,14 @@ services:

web-dev:
image: node:16-alpine
user: 1000:1000
user: "${ANUBIS_UID:-1000}:${ANUBIS_UID:-1000}"
working_dir: /opt/app
command: sh -c 'yarn && yarn run start'
environment:
NODE_ENV: development
REACT_APP_DEV: dev
volumes:
- ./web:/opt/app
ports:
- 127.0.0.1:3000:3000
labels:
- "traefik.enable=true"
- "traefik.http.services.web.loadbalancer.server.port=3000"
Expand Down
4 changes: 2 additions & 2 deletions theia/dockerd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ ENV DOCKER_HOST="tcp://localhost:2376" \

USER 0
RUN set -eux; \
adduser -D -u 1001 theia; \
adduser -D -u 1001 anubis; \
apk add --no-cache supervisor; \
sed -i 's/rootless/theia/' /etc/subuid /etc/subgid;
sed -i 's/rootless/anubis/' /etc/subuid /etc/subgid;

VOLUME /certs

Expand Down
6 changes: 3 additions & 3 deletions theia/sidecar/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM python:3.10-alpine

RUN adduser -D -u 1001 theia \
RUN adduser -D -u 1001 anubis \
&& apk add --update --no-cache git bash \
&& pip3 install --no-cache-dir flask supervisor gunicorn

USER theia
USER anubis
RUN git config --global user.email anubis@anubis-lms.io \
&& git config --global user.name anubis-robot \
&& git config --global credential.store helper \
Expand All @@ -19,7 +19,7 @@ COPY autosave-loop.sh /autosave-loop.sh
COPY autosave.sh /autosave.sh
COPY app.py /app.py

USER theia
USER anubis
ENTRYPOINT ["supervisord", "--nodaemon", "-c", "/supervisord.conf"]


4 changes: 2 additions & 2 deletions theia/sidecar/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile=/tmp/supervisord.log
[program:autosave-loop]
directory=/
command=/autosave-loop.sh
environment=HOME="/home/theia"
environment=HOME="/home/anubis"
autorestart=true
redirect_stderr=true
stdout_logfile=/tmp/autosave.log
Expand All @@ -13,7 +13,7 @@ stdout_logfile=/tmp/autosave.log
directory=/
command=gunicorn -b 0.0.0.0:5001 -w 1 --capture-output --enable-stdio-inheritance app:app
autorestart=true
environment=HOME="/home/theia"
environment=HOME="/home/anubis"
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0

0 comments on commit 1953555

Please sign in to comment.