Skip to content
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

added a basic docker-compose based dev environment #80

Merged
merged 5 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# === Raster Loader Environment Variables ===
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ After creating your environment, you can enter the virtual environment with
``source env/bin/activate`` on Linux and macOS or ``env\bin\Activate.ps1`` on Windows
(PowerShell).


### Setting up your environment (Docker / Docker-Compose)

1. Install Docker and Docker Compose on your system by following the instructions for your operating system from the official Docker website.
2. Use `git clone` to clone [the Raster Loader repository](https://github.com/CartoDB/raster-loader)
to your local machine.
3. Navigate to the root directory of the repository in your terminal.
4. Run `make docker-build` command to build the docker image
5. Run `make docker-start` to start the development environment. Keep this process running.
6. Begin your development in a new terminal.
7. Run `make docker-test` to run the test suite.
8. Run a targeted test using pytest flags: `make docker-test PYTEST_FLAGS='-s -k array'`
9. Run `git checkout -b my-new-feature` to start a new feature branch
10. Consider writing a test in `raster_loader/tests/` to guide your implementation
11. Drop into `pdb` when a test fails: `make docker-test PYTEST_FLAGS='-s --pdb'`
12. Run `make docker-enter` to open a terminal inside of the docker container
13. Run `make docker-stop` to stop the development environment
14. Run `make docker-remove` to remove docker raster_loader Container/Network/Volume from your system

*Note: If you want to make changes to library dependencies (i.e. requirements.txt or requirements-dev.txt) while the container is running, you'll need to rebuild the image using the make docker-build command and restart the container."*

### Tests and linting

Before submitting a pull request, you need to make sure your updates pass tests and
Expand Down
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,29 @@ publish-test-pypi:

clean:
rm -rf $(VENV) $(DIST) $(BUILD) *.egg-info

ENTER_CONTAINER:=docker-compose exec raster_loader

.PHONY: docker-build
docker-build: ## Build necessary stuff.
docker-compose build

.PHONY: docker-start
docker-start: ## Start containers with docker-compose and attach to logs.
docker-compose up --no-build

.PHONY: docker-test
docker-test: ## Enter the running backend container and run tests.
$(ENTER_CONTAINER) sh -c 'cd raster_loader && pytest $(PYTEST_FLAGS)'

.PHONY: docker-enter
docker-enter: ## Enter the backend container.
$(ENTER_CONTAINER) bash

.PHONY: docker-stop
docker-stop: ## Stop all running containers.
docker-compose stop

.PHONY: docker-remove
docker-remove: ## Remove all containers / volumes
docker-compose down --volumes
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.8'

services:
raster_loader:
platform: linux/amd64
image: carto/raster_loader
ports:
- '8888:8888'
build:
context: .
dockerfile: docker/raster_loader/Dockerfile
volumes:
- './:/code'
env_file: ./.env
command: |
sh -c 'tail -f /dev/null'
41 changes: 41 additions & 0 deletions docker/raster_loader/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM osgeo/gdal:3.2.0

ENV HOMEAPP=/code
ENV PATH=$PATH:$HOMEAPP/.local/bin
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

WORKDIR $HOMEAPP/

RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install --no-install-recommends -y \
bash \
build-essential \
gcc \
git \
libpq-dev \
python3-dev \
postgresql-client \
wget \
gdal-bin \
python3-pip \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

# Using a non-privileged user to own our code
RUN useradd -d $HOMEAPP -N non-privileged

# Update non-privileged user folder permission
RUN chown -R non-privileged $HOMEAPP

# Copy the requirements file into the container
COPY requirements.txt .
COPY requirements-dev.txt .
COPY . .

# Install the dependencies
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir -r requirements-dev.txt

# Copy the rest of the files into the container
USER non-privileged