Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit 9a6a661

Browse files
authored
Resolve issue with smoke-test action being run more than once for a workflow
1 parent 638b758 commit 9a6a661

File tree

4 files changed

+101
-90
lines changed

4 files changed

+101
-90
lines changed

.github/actions/smoke-test/action.yaml

Lines changed: 2 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -27,96 +27,9 @@ runs:
2727
- name: Build image
2828
id: build_image
2929
shell: bash
30-
run: |
31-
set -e
32-
33-
export DOCKER_BUILDKIT=1
34-
35-
# Symlink build scripts from main to improve security when testing PRs
36-
if [ -d "$GITHUB_WORKSPACE/__build/build" ]; then
37-
cd "$GITHUB_WORKSPACE/__build"
38-
yarn install
39-
cd "$GITHUB_WORKSPACE"
40-
rm -rf build node_modules
41-
ln -s "$GITHUB_WORKSPACE/__build/build" build
42-
ln -s "$GITHUB_WORKSPACE/__build/node_modules" node_modules
43-
else
44-
echo "WARNING: Using build/vscdc from ${{ github.ref }} instead of main."
45-
yarn install
46-
fi
47-
48-
# Run test build
49-
chmod +x build/vscdc
50-
build/vscdc push ${{ inputs.definition }} \
51-
--no-push \
52-
--release dev \
53-
--github-repo "microsoft/vscode-dev-containers" \
54-
--registry "mcr.microsoft.com" \
55-
--registry-path "vscode/devcontainers" \
56-
--stub-registry "mcr.microsoft.com" \
57-
--stub-registry-path "vscode/devcontainers"
30+
run: ${{ github.action_path }}/build.sh ${{ inputs.definition }}
5831

5932
- name: Test image
6033
id: test_image
6134
shell: bash
62-
run: |
63-
# Run test script for image if one exists
64-
65-
export DOCKER_BUILDKIT=1
66-
67-
if [ "${{ inputs.image }}" = "none" ]; then
68-
echo "Image not specified. Aborting test."
69-
exit 0
70-
fi
71-
72-
set -e
73-
74-
# Update UID/GID for user in container - Actions uses different UID/GID than container
75-
# which causes bind mounts to be read only and cause certain write tests to fail
76-
# The dev container CLI handles this automatically but we're not using it.
77-
local_uid=$(id -u)
78-
local_gid=$(id -g)
79-
echo "(*) Updating container user UID/GID..."
80-
echo -e "FROM ${{ inputs.image }}\n \
81-
RUN export sudo_cmd="" \
82-
&& if [ "$(id -u)" != "0" ]; then export sudo_cmd=sudo; fi \
83-
&& \${sudo_cmd} groupmod -g ${local_gid} ${{ inputs.user }} \
84-
&& \${sudo_cmd} usermod -u ${local_uid} -g ${local_gid} ${{ inputs.user }}" > uid.Dockerfile
85-
cat uid.Dockerfile
86-
docker build -t ${{ inputs.image }}-uid -f uid.Dockerfile .
87-
88-
# Start container
89-
echo "(*) Starting container..."
90-
container_name="vscdc-test-container"
91-
docker run -d --name ${container_name} --rm --init --privileged -v "$(pwd)/containers/${{ inputs.definition }}:/workspace" ${{ inputs.image }}-uid /bin/sh -c 'while sleep 1000; do :; done'
92-
93-
# Fake out existence of extensions, VS Code Server
94-
echo "(*) Stubbing out extensions and VS Code Server..."
95-
dev_container_relative_path="containers/${{ inputs.definition }}/.devcontainer"
96-
mkdir -p "/tmp/${dev_container_relative_path}"
97-
cp -f "$(pwd)/${dev_container_relative_path}/devcontainer.json" "/tmp/${dev_container_relative_path}/"
98-
dev_container_tmp="/tmp/${dev_container_relative_path}/devcontainer.json"
99-
sed -i'.bak' -e "s/\\/\\/.*/ /g" "${dev_container_tmp}"
100-
extensions="$(jq '.extensions' --compact-output "${dev_container_tmp}" | tr -d '[' | tr -d ']' | tr ',' '\n' 2>/dev/null || echo -n '')"
101-
docker exec -u "${{ inputs.user }}" ${container_name} /bin/sh -c "\
102-
mkdir -p \$HOME/.vscode-server/bin \$HOME/.vscode-server/extensions \
103-
&& cd \$HOME/.vscode-server/extensions \
104-
&& if [ \"${extensions}\" != '' ]; then echo \"${extensions}\" | xargs -n 1 mkdir -p; fi \
105-
&& find \$HOME/.vscode-server/ -type d"
106-
107-
# Run actual test
108-
echo "(*) Running test..."
109-
docker exec -u "${{ inputs.user }}" ${container_name} /bin/sh -c '\
110-
set -e \
111-
&& cd /workspace \
112-
&& if [ -f "test-project/test.sh" ]; then \
113-
cd test-project \
114-
&& if [ "$(id -u)" = "0" ]; then \
115-
chmod +x test.sh; \
116-
else \
117-
sudo chmod +x test.sh; \
118-
fi \
119-
&& ./test.sh; \
120-
else \
121-
ls -a;
122-
fi'
35+
run: ${{ github.action_path }}/test.sh ${{ inputs.definition }} ${{ inputs.image }} ${{ inputs.user }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
DEFINITION="$1"
3+
4+
set -e
5+
6+
export DOCKER_BUILDKIT=1
7+
8+
# Symlink build scripts from main to improve security when testing PRs
9+
if [ -d "$GITHUB_WORKSPACE/__build/build" ]; then
10+
cd "$GITHUB_WORKSPACE/__build"
11+
yarn install
12+
cd "$GITHUB_WORKSPACE"
13+
rm -rf build node_modules
14+
ln -s "$GITHUB_WORKSPACE/__build/build" build
15+
ln -s "$GITHUB_WORKSPACE/__build/node_modules" node_modules
16+
else
17+
echo "WARNING: Using build/vscdc from $GITHUB_REF instead of main."
18+
yarn install
19+
fi
20+
21+
# Run test build
22+
chmod +x build/vscdc
23+
build/vscdc push ${DEFINITION} \
24+
--no-push \
25+
--release dev \
26+
--github-repo "microsoft/vscode-dev-containers" \
27+
--registry "mcr.microsoft.com" \
28+
--registry-path "vscode/devcontainers" \
29+
--stub-registry "mcr.microsoft.com" \
30+
--stub-registry-path "vscode/devcontainers"

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#/bin/bash
2+
DEFINITION="$1"
3+
IMAGE="$2"
4+
USERNAME="$3"
5+
6+
# Run test script for image if one exists
7+
8+
export DOCKER_BUILDKIT=1
9+
10+
if [ "${IMAGE}" = "none" ]; then
11+
echo "Image not specified. Aborting test."
12+
exit 0
13+
fi
14+
15+
set -e
16+
17+
# Update UID/GID for user in container - Actions uses different UID/GID than container
18+
# which causes bind mounts to be read only and cause certain write tests to fail
19+
# The dev container CLI handles this automatically but we're not using it.
20+
local_uid=$(id -u)
21+
local_gid=$(id -g)
22+
echo "(*) Updating container user UID/GID..."
23+
echo -e "FROM ${IMAGE}\n \
24+
RUN export sudo_cmd="" \
25+
&& if [ "$(id -u)" != "0" ]; then export sudo_cmd=sudo; fi \
26+
&& \${sudo_cmd} groupmod -g ${local_gid} ${USERNAME} \
27+
&& \${sudo_cmd} usermod -u ${local_uid} -g ${local_gid} ${USERNAME}" > uid.Dockerfile
28+
cat uid.Dockerfile
29+
docker build -t ${IMAGE}-uid -f uid.Dockerfile .
30+
31+
# Start container
32+
echo "(*) Starting container..."
33+
container_name="vscdc-test-container-$DEFINITION"
34+
docker run -d --name ${container_name} --rm --init --privileged -v "$(pwd)/containers/${DEFINITION}:/workspace" ${IMAGE}-uid /bin/sh -c 'while sleep 1000; do :; done'
35+
36+
# Fake out existence of extensions, VS Code Server
37+
echo "(*) Stubbing out extensions and VS Code Server..."
38+
dev_container_relative_path="containers/${DEFINITION}/.devcontainer"
39+
mkdir -p "/tmp/${dev_container_relative_path}"
40+
cp -f "$(pwd)/${dev_container_relative_path}/devcontainer.json" "/tmp/${dev_container_relative_path}/"
41+
dev_container_tmp="/tmp/${dev_container_relative_path}/devcontainer.json"
42+
sed -i'.bak' -e "s/\\/\\/.*/ /g" "${dev_container_tmp}"
43+
extensions="$(jq '.extensions' --compact-output "${dev_container_tmp}" | tr -d '[' | tr -d ']' | tr ',' '\n' 2>/dev/null || echo -n '')"
44+
docker exec -u "${USERNAME}" ${container_name} /bin/sh -c "\
45+
mkdir -p \$HOME/.vscode-server/bin \$HOME/.vscode-server/extensions \
46+
&& cd \$HOME/.vscode-server/extensions \
47+
&& if [ \"${extensions}\" != '' ]; then echo \"${extensions}\" | xargs -n 1 mkdir -p; fi \
48+
&& find \$HOME/.vscode-server/ -type d"
49+
50+
# Run actual test
51+
echo "(*) Running test..."
52+
docker exec -u "${USERNAME}" ${container_name} /bin/sh -c '\
53+
set -e \
54+
&& cd /workspace \
55+
&& if [ -f "test-project/test.sh" ]; then \
56+
cd test-project \
57+
&& if [ "$(id -u)" = "0" ]; then \
58+
chmod +x test.sh; \
59+
else \
60+
sudo chmod +x test.sh; \
61+
fi \
62+
&& ./test.sh; \
63+
else \
64+
ls -a;
65+
fi'
66+
67+
# Clean up
68+
docker rm -f ${container_name}

containers/docker-in-docker/.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Note: You can use any Debian/Ubuntu based image you want.
2-
FROM mcr.microsoft.com/vscode/devcontainers/base:bullseye
2+
FROM mcr.microsoft.com/vscode/devcontainers/base:buster
33

44
# [Option] Install zsh
55
ARG INSTALL_ZSH="true"

0 commit comments

Comments
 (0)