Visual Studio Code (VS Code) provides extensions for working with remote machines. This includes the Remote - Containers that allows developers to use Docker containers as a self-contained development environment.
Using containers has many benefits. It allows developers to maintain a consistent development environment that can be easily moved or copied onto other workstations or by other developers. It creates a sandbox environment that shields your host system from unnecessary software components, that is especialy crucial when experimenting and documenting.
Using this starter kit, an Oracle Developer can quickly get started with developing in Python, within a development container (devcontainer).
- Microsoft Visual Studio Code [Download]
- Remote - Container extension - Install the Remote Development pack or just the extension.
- Docker - Follow the instructions to install Docker Community Edition for your host operating system.
The starter kit runs a Docker container with the following components for Python development:
- Oracle Instant Client Release 19.3
- Oracle SQL*Plus
- Python 3.x
- cx_Oracle
- Oracle Cloud Infrastructure (OCI) Python SDK
- Git
- Microsoft's Python extension for VS Code
- pylint
Place any additional Python libraries required by the project in the requirements.txt
file. Do not include cx_Oracle as it is already included in the Docker build. Packages should be available on the Python Package Index.
The devcontainer installs the VS Code extension for Python and configure pylint as the linter. Add any additional extensions required in the extensions
attribute in the devcontainer.json
file. For example, this adds the Language PL/SQL extension:
"extensions": [ "ms-python.python", "xyz.plsql-language" ]
- Build a Docker image for running an Oracle Database using the instructions found here. Alternatively, for Linux and Mac users, there are scripts in the docker-apex-stack that will facilitate the process and at the same time, provision a full Oracle Application Express (APEX) stack.
- Run a container using the image and attach it to a Docker network.
- Clone the project:
$ git clone https://github.com/fuzziebrain/vscode-remote-oradev-python.git
- Modify the Docker network to attach to, in the
devcontainer.json
. For example, the following parameter attaches the devcontainer to the axer_network typically used with the docker-apex-stack:"--network", "axer_network"
- If a port is required to be exposed, add it to the attribute
appPort
. For example, Flask run on port5000
by default:"appPort": [ 5000 ]
- Open the project directory in VS Code. It should detect the devcontainer and ask whether to reload the folder from within the container.
or
Run the command Remote Containers: Reopen Folder in Container
Customise the Docker container if necessary. To rebuild the container, run the command Remote Containers: Rebuild Container. This command is only available when the folder is opened in a devcontainer.
A debug configuration has been created. See launch.json
.
Developers are encouraged to store database credentials safely in encrypted Oracle Wallets, as oppose to storing them in plaintext either within the Python script or as environment variables. Follow the Oracle Database Connection with Oracle Wallet guide.
See Support for Oracle Cloud Infrasturcture Guide.
The beauty of Open Source is that we can learn and build on top of previous knowledge shared by others. I wish to thank the following projects that have guided the creation of this starter kit:
- Microsoft's Try Out Development Containers: Python
- Oracle's Docker Images
Please see LICENSE.