27
27
- name : Build image
28
28
id : build_image
29
29
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 }}
58
31
59
32
- name : Test image
60
33
id : test_image
61
34
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 }}
0 commit comments