Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit d0a8b23

Browse files
committed
restore use of Dockerfile for devcontainer
1 parent c2c0a97 commit d0a8b23

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

.devcontainer.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
// For format details, see https://aka.ms/devcontainer.json
22
{
33
"name": "Python 3 Developer Container",
4-
"image": "python:3.11",
4+
"build": {
5+
"dockerfile": "Dockerfile",
6+
"target": "build",
7+
"context": ".",
8+
"args": {
9+
"PIP_OPTIONS": "-e .[dev]"
10+
}
11+
},
512
"remoteEnv": {
613
"DISPLAY": "${localEnv:DISPLAY}"
714
},
@@ -19,6 +26,7 @@
1926
"initializeCommand": "bash -c 'for i in $HOME/.inputrc; do [ -f $i ] || touch $i; done'",
2027
"runArgs": [
2128
"--net=host",
29+
"--security-opt=label=type:container_runtime_t",
2230
"-v=${localEnv:HOME}/.ssh:/root/.ssh",
2331
"-v=${localEnv:HOME}/.inputrc:/root/.inputrc"
2432
],
@@ -28,7 +36,5 @@
2836
],
2937
// make the workspace folder the same inside and outside of the container
3038
"workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind",
31-
"workspaceFolder": "${localWorkspaceFolder}",
32-
// After the container is created, install the python project in editable form
33-
"postCreateCommand": "pip install -e .[dev]"
39+
"workspaceFolder": "${localWorkspaceFolder}"
3440
}

.github/workflows/code.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ jobs:
104104
install_options: dist/*.whl
105105

106106
- name: Test module --version works using the installed wheel
107-
run: |
108-
# If more than one module in src/ replace with module name to test
109-
python -m $(ls src | head -1) --version
107+
# If more than one module in src/ replace with module name to test
108+
run: python -m $(ls src | head -1) --version
110109

111110
container:
112111
needs: [lint, dist, test]
@@ -151,6 +150,8 @@ jobs:
151150
- name: Build runtime image
152151
uses: docker/build-push-action@v3
153152
with:
153+
build-args: |
154+
PIP_OPTIONS=-r lockfiles/requirements.txt dist/*.whl
154155
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
155156
load: ${{ ! (github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) }}
156157
tags: ${{ steps.meta.outputs.tags }}

Dockerfile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
# This file is for use as a runtime container only, it depends on dist/
2-
# and lockfiles being made outside the container
3-
FROM python:3.11-slim as base
1+
# This file is for use as a devcontainer and a runtime container
2+
#
3+
# The devcontainer should use the build target and run as root with podman
4+
# or docker with user namespaces.
5+
#
6+
FROM python:3.11 as base
47
FROM base as build
58

9+
ARG PIP_OPTIONS
10+
611
# Add any system dependencies for the developer/build environment here e.g.
712
# RUN apt-get update && apt-get upgrade -y && \
813
# apt-get install -y --no-install-recommends \
@@ -17,10 +22,10 @@ ENV PATH=/venv/bin:$PATH
1722
COPY . /project
1823
WORKDIR /project
1924

20-
# install the wheel
21-
RUN pip install -r lockfiles/requirements.txt dist/*.whl
25+
# install python package into /venv
26+
RUN pip install ${PIP_OPTIONS}
2227

23-
FROM base as runtime
28+
FROM python:3.11-slim as runtime
2429

2530
# Add apt-get system dependecies for runtime here if needed
2631

0 commit comments

Comments
 (0)