-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add dev-containers and their environment #33
base: main
Are you sure you want to change the base?
Conversation
README.md
Outdated
To start the containers, just run `docker-compose up` (or `docker-compose up -d` if you want to run the containers in background); or `docker-compose create` and `docker-compose start` if you don't want to see the logs. | ||
Once the containers are running, you can go to `http://localhost:8000/docs` to see the automatic interactive API documentation. | ||
|
||
The only things you need are [Docker](https://docs.docker.com/engine/install/), [Docker Compose](https://docs.docker.com/compose/install/), and [Visual Studio Code](https://code.visualstudio.com/download). Once you open the template with VS Code, it will recommend that you install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) if you don’t have it already. Then, a pop-up will appear to reopen the template in the devcontainer, or you can use `Ctrl / Cmd + shift + P` -> `Dev Containers: Open Folder in Container…`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only things you need are [Docker](https://docs.docker.com/engine/install/), [Docker Compose](https://docs.docker.com/compose/install/), and [Visual Studio Code](https://code.visualstudio.com/download). Once you open the template with VS Code, it will recommend that you install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) if you don’t have it already. Then, a pop-up will appear to reopen the template in the devcontainer, or you can use `Ctrl / Cmd + shift + P` -> `Dev Containers: Open Folder in Container…`. | |
The only things you need are [Docker](https://docs.docker.com/engine/install/), [Docker Compose](https://docs.docker.com/compose/install/), and a code editor with devcontainer support like [Visual Studio Code](https://code.visualstudio.com/download). Once you open the template with VS Code, it will recommend that you install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) if you don’t have it already. Then, a pop-up will appear to reopen the template in the devcontainer, or you can use `Ctrl / Cmd + shift + P` -> `Dev Containers: Open Folder in Container…`. |
README.md
Outdated
|
||
Once the containers and server are running, you can go to `http://localhost:8000/docs` to see the automatic interactive API documentation. | ||
|
||
In case you don't to use VS Code and dev containers, or you want to set up the environment in a different way. You must have `Python >3.11`, [Poetry](https://python-poetry.org/docs/#installation) (don't forget to install the dependencies from the lock file), and a [PostgreSQL](https://www.postgresql.org/) database, setting the corresponding environment variables for the database connection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit.... lists help me to follow steps 😅
In case you don't to use VS Code and dev containers, or you want to set up the environment in a different way. You must have `Python >3.11`, [Poetry](https://python-poetry.org/docs/#installation) (don't forget to install the dependencies from the lock file), and a [PostgreSQL](https://www.postgresql.org/) database, setting the corresponding environment variables for the database connection. | |
In case you don't to use VS Code and dev containers, or you want to set up the environment in a different way. You must have | |
- `Python >3.11` | |
- [Poetry](https://python-poetry.org/docs/#installation) (don't forget to install the dependencies from the lock file) | |
- [PostgreSQL](https://www.postgresql.org/) database, setting the corresponding environment variables for the database connection. |
.devcontainer/Dockerfile
Outdated
@@ -0,0 +1,10 @@ | |||
FROM python:3.11-slim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw in the other PR @marianogigli is trying to update it to 3.13 https://github.com/xmartlabs/python-template/pull/32/files#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557L1
did you have a chance to try it here, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can include the upgrade for python in this PR and check if everything works as expected.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, sounds good
.devcontainer/Dockerfile
Outdated
@@ -0,0 +1,10 @@ | |||
FROM python:3.11-slim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can include the upgrade for python in this PR and check if everything works as expected.
What do you think?
.dockerignore
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn´t we include the .dockerignore file in the .devcontainer file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the context of devcontainers, I'm not sure if it's worth it because we're mounting the entire repo as a volume, and we're not doing any COPY or anything similar. Maybe when we add other Dockerfiles it will be worth it, but I'm not sure if I explained myself well or what do you think?
@@ -0,0 +1,26 @@ | |||
services: | |||
devcontainer: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about include the env_file
attribute in case someone whats to add new variables in their project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the env vars using the property containerEnv
of the devcontainers.json
file. New ones can be added there, or we can use "runArgs": ["--env-file",".devcontainer/env_file.env"]
to add them from a file (or in the docker-compose), or we can do both to have an example. What do you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest defining it here as more people will know where to look for it. Also one question, is env variables interpolation available if you define it in the json file? That may be another reason for having it in an .env
file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
env
file added. If the same variable is defined in both the .env
file and the .json
file, for example, the devcontainer will take the value from the json file
Dockerfile
Outdated
@@ -0,0 +1,25 @@ | |||
FROM python:3.11-slim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try 3.13 here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NICE CATCH, I just restored the file and forgot to update the version
.devcontainer/.env.example
Outdated
LOG_LEVEL=DEBUG | ||
SERVER_URL=example.com | ||
ACCESS_TOKEN_EXPIRE_MINUTES=15 | ||
JWT_SIGNING_KEY= | ||
JWT_SIGNING_KEY= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JWT_SIGNING_KEY= | |
JWT_SIGNING_KEY= | |
], | ||
"unwantedRecommendations": [] | ||
}, | ||
"postCreateCommand": "cat /workspace/.devcontainer/aliases-devcontainer >> ~/.bashrc", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
.devcontainer/devcontainer.json
Outdated
"forwardPorts": [ | ||
// Backend API: | ||
// localhost:8000 | ||
"devcontainer:8000", | ||
// Postgres: | ||
// localhost:5432 for accessing postgres via local dbeaver/psql client | ||
"postgres:5432" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"forwardPorts": [ | |
// Backend API: | |
// localhost:8000 | |
"devcontainer:8000", | |
// Postgres: | |
// localhost:5432 for accessing postgres via local dbeaver/psql client | |
"postgres:5432" | |
"forwardPorts": [ | |
// Backend API: | |
// localhost:8000 for accessing on your host | |
"devcontainer:8000", | |
// Postgres: | |
// localhost:5432 for accessing postgres via local dbeaver/psql client | |
"postgres:5432" |
❤️ |
Type of change
Description of the change
The VS Code dev-containers are added. Everything related and necessary is placed in the
.devcontainers
folder. Then, I delete everything we previously had related to Docker, as it is no longer needed to bring up the template, and in a future PR, this will be rethought.Also, some necessary modifications are made due to the dev-containers, for example, the
README.d
is adjusted, and theexec.sh
file is modified.Related PRs
N/A