-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make docker and docker-compose work on WSL2 (#1375)
### Summary > Describe your changes. Fixes the docker-compose steps to work on WSL2 (Windows Subsystem for Linux 2) and OSX. Updates documentation to use the new cncf tag when building the container. docker-compose is very helpful for dev setups and trying out cartography. ### Checklist ### Testing performed I started with a fresh clone of this branch and on _both_ OSX and WSL2ran 1. `docker build -t cartography-cncf/cartography-dev -f dev.Dockerfile ./` 1. `docker-compose run cartography-dev make test` I can confirm that both paths worked and ran the full test suite using docker-compose. #### WSL2 Linter: ![image](https://github.com/user-attachments/assets/b165feb6-0d0a-4a9c-90dd-fe47e8390b0d) Unit tests: ![image](https://github.com/user-attachments/assets/4cfa8a41-6775-4ac1-ad9c-6052163c0a17) Integration tests: ![image](https://github.com/user-attachments/assets/f134dec5-8df2-4c9b-a7f6-57cccac51f89) #### OSX Linter: <img width="1000" alt="Screenshot 2024-11-03 at 12 29 49 AM" src="https://github.com/user-attachments/assets/e7840c2a-8065-4163-8057-3de902532291"> Unit tests: <img width="997" alt="Screenshot 2024-11-03 at 12 30 07 AM" src="https://github.com/user-attachments/assets/11d91723-776c-4438-b2a1-fe783e75e414"> Integration tests: <img width="1003" alt="Screenshot 2024-11-03 at 12 30 22 AM" src="https://github.com/user-attachments/assets/c2360ad5-a2c2-4309-91d0-1080dc9d0bb3"> --------- Signed-off-by: Alex Chantavy <[email protected]>
- Loading branch information
Showing
8 changed files
with
51 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# This .gitignore is a placeholder so that we can store .cache/ in github. | ||
# We are including a pre-created .cache in Github so that when | ||
# we run docker-compose in WSL2 during dev linting, WSL2 does not attempt | ||
# to create .cache/ with root as the owner. The contents of .cache | ||
# should never be pushed back upstream to the main cartography repo. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# This file is for use with docker compose so that mounting Neo4j volumes doesn't fail with perms errs | ||
GID=10001 | ||
UID=10001 | ||
# This file is for docker-compose dev use so that mounting | ||
# Neo4j volumes doesn't fail with permissions errors. | ||
GID=1000 | ||
UID=1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
# Builds cartography container for development by performing a Python editable install of the current source code. | ||
# This image is for dev only. | ||
# Performs a Python editable install of the current Cartography source. | ||
# Assumptions: | ||
# - This dockerfile will get called with .cache as a volume mount. | ||
# - The current working directory on the host building this container | ||
# is the cartography source tree from github. | ||
FROM python:3.10-slim | ||
|
||
# the UID and GID to run cartography as | ||
# (https://github.com/hexops/dockerfile#do-not-use-a-uid-below-10000). | ||
ARG uid=10001 | ||
ARG gid=10001 | ||
# The UID and GID to run cartography as. | ||
# This needs to match the gid and uid on the host. | ||
# Update this to match. On WSL2 this is usually 1000. | ||
ARG uid=1000 | ||
ARG gid=1000 | ||
|
||
RUN apt-get update && \ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends make git && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Assumption: current working directory is the cartography source tree from github. | ||
COPY . /var/cartography | ||
# Install dependencies. | ||
WORKDIR /var/cartography | ||
ENV HOME=/var/cartography | ||
COPY . /var/cartography | ||
RUN pip install -r test-requirements.txt && \ | ||
pip install -U -e . && \ | ||
chmod -R a+w /var/cartography | ||
|
||
RUN pip install -U -e . && \ | ||
pip install -r test-requirements.txt && \ | ||
# Grant write access to the directory for unit and integration test coverage files | ||
chmod -R a+w /var/cartography && \ | ||
# Sets the directory as safe due to a mismatch in the user that cloned the repo | ||
# and the user that is going to run the unit&integ tests. This lets pre-commit work. | ||
git config --global --add safe.directory /var/cartography && \ | ||
# Now copy the entire source tree. | ||
ENV HOME=/var/cartography | ||
# Necessary for pre-commit. | ||
RUN git config --global --add safe.directory /var/cartography && \ | ||
git config --local user.name "cartography" | ||
|
||
USER ${uid}:${gid} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters