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

Add dev-containers and their environment #33

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

gastonsalgueiro
Copy link

@gastonsalgueiro gastonsalgueiro commented Nov 21, 2024

Type of change

  • Fix
  • Story
  • Chore

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 the exec.sh file is modified.

Related PRs

N/A

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…`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

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 😅

Suggested change
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.

@@ -0,0 +1,10 @@
FROM python:3.11-slim
Copy link
Contributor

@MBerguer MBerguer Nov 21, 2024

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?

Copy link
Collaborator

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, sounds good

@@ -0,0 +1,10 @@
FROM python:3.11-slim
Copy link
Collaborator

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
Copy link
Collaborator

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?

Copy link
Author

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:
Copy link
Collaborator

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?

Copy link
Author

@gastonsalgueiro gastonsalgueiro Nov 27, 2024

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?

Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

envfile 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

@marianogigli marianogigli mentioned this pull request Jan 15, 2025
3 tasks
Dockerfile Outdated
@@ -0,0 +1,25 @@
FROM python:3.11-slim
Copy link
Contributor

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?

Copy link
Author

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

LOG_LEVEL=DEBUG
SERVER_URL=example.com
ACCESS_TOKEN_EXPIRE_MINUTES=15
JWT_SIGNING_KEY=
JWT_SIGNING_KEY=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
JWT_SIGNING_KEY=
JWT_SIGNING_KEY=

],
"unwantedRecommendations": []
},
"postCreateCommand": "cat /workspace/.devcontainer/aliases-devcontainer >> ~/.bashrc",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Comment on lines 46 to 52
"forwardPorts": [
// Backend API:
// localhost:8000
"devcontainer:8000",
// Postgres:
// localhost:5432 for accessing postgres via local dbeaver/psql client
"postgres:5432"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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"

src/admin.py Show resolved Hide resolved
@federicoVallcorbaX
Copy link
Contributor

❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants