diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4788f0498..6ba1e733e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,15 +5,45 @@ // Sets the run context to one level up instead of the .devcontainer folder. "context": "..", // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. - "dockerFile": "../Dockerfile.vscode", - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - // Uncomment the next line to run commands after the container is created - for example installing curl. - // "postCreateCommand": "apt-get update && apt-get install -y curl", - // Uncomment when using a ptrace-based debugger like C++, Go, and Rust - // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], - // Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker. - // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], - // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "vscode" + "dockerFile": "../Dockerfile", + // make sure you don't have any local .venv in wps/api or it won't work + // note: we don't use a workspace mount because then you'll only see the files in /api, when + // you probably want to see everything. This means you must cd from /workspace to /app in order + // to actually run things though. the following mount will at least make the /app folder in the + // docker container change when files in api change. + "mounts": [ + "source=${localWorkspaceFolder}/api,target=/app,type=bind" + ], + "remoteUser": "worker", + "containerUser": "worker", + "updateRemoteUserUID": false, // without this you wind up as ubuntu user + // this lets the container access the database container. On linux I had to configure the db + // host to localhost for it to work in the .env file in api/app + // tested with the database running from the docker-compose file with `docker compose up db` + "forwardPorts": [ + 8080 + ], + "runArgs": [ + "--network=host", + "--platform", + "linux/amd64", + "--hostname=wps-dev", + ], + // sets us in the correct location, and install dev requirements like pytest + "postCreateCommand": "echo 'cd /app' >> ~/.bashrc && cd /app && poetry install", + // by default the dockerfile sets the shell to /bin/sh - you can use whatever you like here + // but if you use bash, it will automatically set you in the /app folder rather than workspace + // when the terminal connects + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.defaultProfile.linux": "bash", + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/bin/bash" + } + } + } + } + } } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f40590efb..788ecbf9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG DOCKER_IMAGE=image-registry.openshift-image-registry.svc:5000/e1e498-tools/wps-api-base:02-10-2024 +ARG DOCKER_IMAGE=ghcr.io/bcgov/wps/wps-api-base:10-21-2024 # To build locally, point to a local base image you've already built (see openshift/wps-api-base) # e.g. : docker build --build-arg DOCKER_IMAGE=wps-api-base:my-tag . @@ -70,8 +70,8 @@ COPY ./api/alembic.ini /app COPY ./api/prestart.sh /app COPY ./api/start.sh /app -# Copy installed Python packages -COPY --from=builder /home/worker/.cache/pypoetry/virtualenvs /home/worker/.cache/pypoetry/virtualenvs +# Copy installed Python packages (the chown lets us install the dev packages later without root if we want) +COPY --from=builder --chown=$USERNAME:$USER_GID /home/worker/.cache/pypoetry/virtualenvs /home/worker/.cache/pypoetry/virtualenvs # The fastapi docker image defaults to port 80, but openshift doesn't allow non-root users port 80. EXPOSE 8080 diff --git a/Dockerfile.vscode b/Dockerfile.vscode deleted file mode 100644 index e408f451a..000000000 --- a/Dockerfile.vscode +++ /dev/null @@ -1,88 +0,0 @@ -# NOTE: -# This Dockerfile is for local development only! - -# debian would match more closely what we have in production, and would probably be ideal, -# but it's also a pain working with because debian is so old. -FROM ubuntu:22.04 - -ARG USERNAME=vscode -ARG USER_UID=1000 -ARG USER_GID=$USER_UID - -# Tell r-base not to wait for interactive input. -ENV DEBIAN_FRONTEND=noninteractive - -# Install dependancies needed by python developer packages -# One should really run all these installs and the update in one go - for a consistent install -# but ease of development trumps consistency in this instance: it's easer to have more -# faster running steps that can fail, that one big monster install that takes forever -# and fails. -# NOTE: Once we no longer need pyodbc, please remove the apt-get update and install commands below. -RUN apt-get -y update -RUN apt-get -y install unixodbc-dev -# Install old (2.4.*; current debian) version of gdal -RUN apt-get -y install libgdal-dev -# Dependency required for installation of cffdrs -RUN apt-get -y install libudunits2-dev - -# Install R -RUN apt-get update --fix-missing && apt-get -y install r-base - -# Install cffdrs -RUN R -e "install.packages('cffdrs')" - -# Install some other dependancies -RUN apt-get -y install git build-essential python3 python3-dev python3-pip curl vim - -# Install JDK -RUN apt-get -y install openjdk-11-jdk - -# We could install poetry manually, but it's easier to use apt. -RUN apt-get -y install python3-poetry -# Poetry expects "python", but by default, on ubuntu, you need to specify "python3", so -# we work around that, by using the python3-poetry command. -RUN apt-get -y install python-is-python3 - -# I prefer zsh to bash -RUN apt-get -y install zsh - -# from: https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user -RUN groupadd --gid $USER_GID $USERNAME \ - && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME - -# RUN mkdir /vscode -# RUN chown vscode /vscode -USER $USERNAME -ENV PATH="/home/${USERNAME}/.local/bin:${PATH}" - -WORKDIR /home/$USERNAME - -# Update pip -RUN python3 -m pip install --upgrade pip -RUN python3 -m pip install cachecontrol - -# I like oh-my-zsh: -RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" -# BUT - for some reason git+zsh == slowness, so tell git not to slow down zsh: -# git config --add oh-my-zsh.hide-dirty 1 - -# Copy poetry files. -# COPY pyproject.toml poetry.lock ./ - -# COPY --chown=worker:worker poetry.lock pyproject.toml ./ - -# RUN poetry install - -# # We can't have this inside pyproject.toml because the gdal version differs from platform to platform. -# # To figure out what version of pygdal you need, run gdal-config -# RUN poetry run python -m pip install pygdal==3.4.1.10 - -# COPY ./app /app/app -# RUN mkdir /app/libs -# COPY ./libs /app/libs - -EXPOSE 8080 3000 - -# ENV CLASSPATH=/app/libs/REDapp_Lib.jar:/app/libs/WTime.jar:/app/libs/hss-java.jar:${CLASSPATH} -# CMD PYTHONPATH=. poetry run alembic upgrade head && poetry run uvicorn app.main:app --host 0.0.0.0 --reload --port 8080 -