Skip to content

Commit c930750

Browse files
[universal] - Issue universal config change for non-root default codespace user and installing google chrome browser reuse sandbox to run puppeteer cli in universal image (#1287)
* Changing config to force 1001 as UID for codespace in universal image * Forcing the UID as 1001 for codespace user in universal image * Fixing puppeteer code on the --no-sandbox option to to make it work in ubuntu 24.04 * Trying with different image version for runner. * Reverting back the ubuntu version change for runer * Setting updateRemoteUserUID flag to false. * Reverting back the puppeteer fix to ensure the issue is isolated. * Another fix for puppeteer cli. * Changes done to make google chrome installation a part of the universal image and setting postCreateCommand instead of postStartCommand. * Commit again * Small change to ensure postCreateCoammend doesn't fail when /workspaces/images directory doesn't exist. * Making change to change the UID workaround. * Check the increased image size. * Further change for UID issue fix. Passing the UID & GID of host machine from GitHub action workflow. * Removing commented lines & debug statements * Changing the test.sh back to the original version * Changing the remoteEnv to ContainerEnv as per review comments. * Rmoving the UID & GID change, adding workaround for the test & changing the size check test. * Updating the check size test logic for universal image * Making the image size check more generic as per comments. --------- Co-authored-by: Daniel Doyle <[email protected]>
1 parent cd4daf6 commit c930750

File tree

11 files changed

+39
-14
lines changed

11 files changed

+39
-14
lines changed

.github/actions/smoke-test/build.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export DOCKER_BUILDKIT=1
77
echo "(*) Installing @devcontainer/cli"
88
npm install -g @devcontainers/cli
99

10-
echo "(*) Building image - ${IMAGE}"
1110
id_label="test-container=${IMAGE}"
11+
id_image="${IMAGE}-test-image"
12+
echo "(*) Building image - ${IMAGE}"
13+
devcontainer build --image-name ${id_image} --workspace-folder "src/${IMAGE}/"
14+
echo "(*) Starting container - ${IMAGE}"
1215
devcontainer up --id-label ${id_label} --workspace-folder "src/${IMAGE}/"
16+

.github/actions/smoke-test/check-image-size.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ install_bc() {
3232
check_image_size() {
3333
IMAGE="$1"
3434
THRESHOLD_IN_GB="$2"
35-
35+
id_image="$3"
3636
# call install_bc
3737
install_bc
3838

39-
CONTAINER_ID=$(docker ps -q --filter "label=test-container=$IMAGE")
40-
# Find the image ID of the container
41-
IMAGE_ID=$(docker inspect --format='{{.Image}}' "$CONTAINER_ID")
39+
#Read the image id of the original image, not the modified image with uid and gid
40+
IMAGE_ID=$(docker images -q --filter=reference="$id_image")
4241
# Find the size of the image
4342
IMAGE_SIZE=$(docker image inspect --format='{{.Size}}' "$IMAGE_ID")
4443
# Output the size

.github/actions/smoke-test/test.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ set -e
1010
# Run actual test
1111
echo "(*) Running test..."
1212
id_label="test-container=${IMAGE}"
13+
id_image="${IMAGE}-test-image"
1314
devcontainer exec --workspace-folder $(pwd)/src/$IMAGE --id-label ${id_label} /bin/sh -c 'set -e && if [ -f "test-project/test.sh" ]; then cd test-project && if [ "$(id -u)" = "0" ]; then chmod +x test.sh; else sudo chmod +x test.sh; fi && ./test.sh; else ls -a; fi'
1415

1516
echo "(*) Docker image details..."
1617
docker images
1718
# Checking size of universal image
1819

1920
if [ $IMAGE == "universal" ]; then
20-
check_image_size $IMAGE $THRESHOLD_IN_GB
21+
check_image_size $IMAGE $THRESHOLD_IN_GB $id_image
2122
fi
2223

2324
# Clean up

.github/workflows/push-dev.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
- name: Checkout
3030
id: checkout
3131
uses: actions/checkout@v3
32+
3233

3334
- name: Build and push dev tags
3435
id: build_and_push
@@ -40,7 +41,7 @@ jobs:
4041
STUB_REGISTRY_BASE_PATH: ${{ secrets.STUB_REGISTRY_BASE_PATH }}
4142
SECONDARY_REGISTRY_BASE_PATH: ${{ secrets.SECONDARY_REGISTRY_BASE_PATH }}
4243
TOKEN_NAME: ${{ secrets.TOKEN_NAME }}
43-
PASSWORD: ${{ secrets.PASSWORD }}
44+
PASSWORD: ${{ secrets.PASSWORD }}
4445
run: |
4546
set -e
4647

.github/workflows/push-manual-dev.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
with:
3737
path: 'release'
3838
ref: ${{ github.event.inputs.release }}
39-
39+
4040
- name: Build and push
4141
id: build_and_push
4242
env:

.github/workflows/push.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
2929
- name: Checkout
3030
id: checkout
31-
uses: actions/checkout@v3
31+
uses: actions/checkout@v3
3232

3333
- name: Get tag name
3434
run: echo "TAG=$(echo "${{ github.ref }}" | grep -oP 'refs/tags/\K(.+)')" >> $GITHUB_ENV

.github/workflows/smoke-universal.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ jobs:
1919
- name: Checkout
2020
id: checkout
2121
uses: actions/checkout@v3
22+
2223
- name: Smoke test
2324
env:
24-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2526
id: smoke_test
2627
uses: ./.github/actions/smoke-test
2728
with:

src/universal/.devcontainer/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ RUN apt-get update \
6969
# Install tools and shells not in common script
7070
&& apt-get install -yq vim vim-doc xtail software-properties-common libsecret-1-dev \
7171
# Install additional tools (useful for 'puppeteer' project)
72+
# Also added three new libraries to ensure google chrome sucessful installation
7273
&& apt-get install -y --no-install-recommends libnss3 libnspr4 libatk-bridge2.0-0 libatk1.0-0 libx11-6 libpangocairo-1.0-0 \
73-
libx11-xcb1 libcups2 libxcomposite1 libxdamage1 libxfixes3 libpango-1.0-0 libgbm1 libgtk-3-0 \
74+
libx11-xcb1 libcups2 libxcomposite1 libxdamage1 libxfixes3 libpango-1.0-0 libgbm1 libgtk-3-0 fonts-liberation libvulkan1 xdg-utils \
7475
# Clean up
7576
&& apt-get autoremove -y && apt-get clean -y \
7677
# Move first run notice to right spot

src/universal/.devcontainer/devcontainer.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"ghcr.io/devcontainers/features/common-utils:2": {
88
"username": "codespace",
99
"userUid": "1000",
10-
"userGid": "1000"
10+
"userGid": "1000"
1111
},
1212
"ghcr.io/devcontainers/features/dotnet:2": {
1313
"version": "8.0",
@@ -103,7 +103,11 @@
103103
],
104104
"remoteUser": "codespace",
105105
"containerUser": "codespace",
106-
106+
// This variable is set to ensure puppeteer library gets the sandbox location by default.
107+
// Ref:- https://github.com/devcontainers/internal/issues/249
108+
"containerEnv": {
109+
"CHROME_DEVEL_SANDBOX": "/usr/local/sbin/chrome-devel-sandbox"
110+
},
107111
// Use 'forwardPorts' to make a list of ports inside the container available locally.
108112
// "forwardPorts": [],
109113

src/universal/.devcontainer/local-features/setup-user/install.sh

+12
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,16 @@ bash -c ". /usr/local/share/nvm/nvm.sh && nvm use 18"
9696
bash -c "npm -g install -g [email protected]"
9797
bash -c ". /usr/local/share/nvm/nvm.sh && nvm use stable"
9898

99+
# Installing google chrome to use the sandbox for launching browser using puppeteer library in nodejs.
100+
# Ref:- https://github.com/devcontainers/internal/issues/249
101+
cd /
102+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
103+
dpkg -i google-chrome-stable_current_amd64.deb
104+
cd /opt/google/chrome/
105+
chown root:root chrome-sandbox
106+
chmod 4755 chrome-sandbox
107+
cp -p chrome-sandbox /usr/local/sbin/chrome-devel-sandbox
108+
cd /
109+
rm -f google-chrome-stable_current_amd64.deb
110+
99111
echo "Done!"

src/universal/test-project/test.sh

100644100755
+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
cd $(dirname "$0")
33

44
source test-utils.sh codespace
5+
#Changing he ownership of dotnet path to ensure oryx-install-dotnet-2.1 test doesn't fail with permission issue
6+
sudo chown -R codespace:codespace /usr/share/dotnet
57

68
# Run common tests
79
checkCommon
@@ -202,4 +204,4 @@ check "conda-install-tensorflow" bash -c "conda create --name test-env -c conda-
202204
check "conda-install-pytorch" bash -c "conda create --name test-env -c conda-forge --yes pytorch"
203205

204206
# Report result
205-
reportResults
207+
reportResults

0 commit comments

Comments
 (0)