diff --git a/.github/actions/smoke-test/action.yaml b/.github/actions/smoke-test/action.yaml index c09f7388e..b54cc78d5 100644 --- a/.github/actions/smoke-test/action.yaml +++ b/.github/actions/smoke-test/action.yaml @@ -4,14 +4,6 @@ inputs: description: 'Definition to test' required: true default: 'debian' - image: - description: 'Image to run smoke test in' - required: true - default: 'none' - user: - description: 'User in container image to use for smoke test' - required: true - default: 'vscode' runs: using: composite @@ -32,4 +24,4 @@ runs: - name: Test image id: test_image shell: bash - run: ${{ github.action_path }}/test.sh ${{ inputs.definition }} ${{ inputs.image }} ${{ inputs.user }} + run: ${{ github.action_path }}/test.sh ${{ inputs.definition }} diff --git a/.github/actions/smoke-test/build.sh b/.github/actions/smoke-test/build.sh index fde6072b5..b9f983708 100755 --- a/.github/actions/smoke-test/build.sh +++ b/.github/actions/smoke-test/build.sh @@ -4,23 +4,14 @@ DEFINITION="$1" set -e export DOCKER_BUILDKIT=1 +echo "(*) Pulling latest '@devcontainer/cli" +# npm install -g @devcontainers/cli -# Symlink build scripts from main to improve security when testing PRs -if [ -d "$GITHUB_WORKSPACE/__build/build" ]; then - cp -r "$GITHUB_WORKSPACE/__build/build" "$GITHUB_WORKSPACE/" -else - echo "WARNING: Using build/vscdc from $GITHUB_REF instead of main." -fi -rm -rf node_modules -yarn install +#Temporarily installing cli from source until https://github.com/devcontainers/cli/pull/6 is merged +cd build +chmod +x devcontainers-cli-0.3.0-1.tgz + +echo "(*) Building image - ${DEFINITION}" +npx --yes devcontainers-cli-0.3.0-1.tgz up --workspace-folder ../src/${DEFINITION} +# devcontainer build --workspace-folder "src/${DEFINITION}/" --image-name vsc-${DEFINITION} -# Run test build -chmod +x build/vscdc -build/vscdc push ${DEFINITION} \ - --no-push \ - --release dev \ - --github-repo "devcontainers/images" \ - --registry "mcr.microsoft.com" \ - --registry-path "devcontainers" \ - --stub-registry "mcr.microsoft.com" \ - --stub-registry-path "devcontainers" diff --git a/.github/actions/smoke-test/test.sh b/.github/actions/smoke-test/test.sh index 6df4b4afe..57720ebbb 100755 --- a/.github/actions/smoke-test/test.sh +++ b/.github/actions/smoke-test/test.sh @@ -1,52 +1,15 @@ #/bin/bash DEFINITION="$1" -IMAGE="$2" -USERNAME="$3" export DOCKER_BUILDKIT=1 set -e -# List docker images -echo "(*) Listing docker images..." -docker images - - -# Update UID/GID for user in container - Actions uses different UID/GID than container -# which causes bind mounts to be read only and cause certain write tests to fail -# The dev container CLI handles this automatically but we're not using it. -local_uid=$(id -u) -local_gid=$(id -g) - -echo "(*) Updating container user UID/GID..." -echo -e "FROM ${IMAGE}\n \ - RUN export sudo_cmd="" \ - && if [ "$(id -u)" != "0" ]; then export sudo_cmd=sudo; fi \ - && \${sudo_cmd} groupmod -g ${local_gid} ${USERNAME} \ - && \${sudo_cmd} usermod -u ${local_uid} -g ${local_gid} ${USERNAME}" > uid.Dockerfile -cat uid.Dockerfile -docker build -t ${IMAGE}-uid -f uid.Dockerfile . - -# Start container -echo "(*) Starting container..." -container_name="vscdc-test-container-$DEFINITION" -docker run -d --name ${container_name} --rm --init --privileged -v "$(pwd)/src/${DEFINITION}:/workspace" ${IMAGE}-uid /bin/sh -c 'while sleep 1000; do :; done' - # Run actual test echo "(*) Running test..." -docker exec -u "${USERNAME}" ${container_name} /bin/sh -c '\ - set -e \ - && cd /workspace \ - && 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' +cd build +chmod +x devcontainers-cli-0.3.0-1.tgz + +npx --yes devcontainers-cli-0.3.0-1.tgz exec --workspace-folder $(pwd)/../src/$DEFINITION /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' # Clean up -docker rm -f ${container_name} \ No newline at end of file +docker stop $(docker container ls -q) diff --git a/.github/workflows/push-dev.yml b/.github/workflows/push-dev.yml index 293f282fe..dbfe58fb2 100644 --- a/.github/workflows/push-dev.yml +++ b/.github/workflows/push-dev.yml @@ -62,49 +62,10 @@ jobs: --stub-registry ${{ secrets.STUB_REGISTRY }} \ --stub-registry-path ${{ secrets.STUB_REGISTRY_BASE_PATH }} - package: - name: Package - if: "!contains(github.event.head_commit.message, 'Automated update') && !contains(github.event.head_commit.message, 'CI ignore')" - needs: [build-and-push] - runs-on: ubuntu-latest - steps: - - name: Checkout - id: checkout - uses: actions/checkout@v1 - - - name: Package - id: package - run: | - set -e - yarn install - GIT_BRANCH=$(echo "${{ github.ref }}" | grep -oP 'refs/(heads|tags)/\K(.+)') - if [ "$GIT_BRANCH" == "" ]; then - GIT_BRANCH=main - fi - build/vscdc pack --prep-and-package-only \ - --release $GIT_BRANCH \ - --github-repo ${{ github.repository }} \ - --registry ${{ secrets.REGISTRY }} \ - --registry-path ${{ secrets.REGISTRY_BASE_PATH }} \ - --stub-registry ${{ secrets.STUB_REGISTRY }} \ - --stub-registry-path ${{ secrets.STUB_REGISTRY_BASE_PATH }} - - # Set an output with the resulting package name for upload - PKG_PREFIX=$(node -p "require('./package.json').name") - PKG_NAME=$PKG_PREFIX-${{ github.sha }}.tgz - mv ./$PKG_PREFIX-*.tgz ./$PKG_NAME - echo "::set-output name=package_name::$PKG_NAME" - - - name: Upload package - uses: actions/upload-artifact@v1.0.0 - with: - name: ${{ steps.package.outputs.package_name }} - path: ./${{ steps.package.outputs.package_name }} - image-info: name: Trigger info extraction if: "!contains(github.event.head_commit.message, 'Automated update') && !contains(github.event.head_commit.message, 'CI ignore')" - needs: [package] + needs: [build-and-push] runs-on: ubuntu-latest steps: - name: Trigger image info file generation diff --git a/.github/workflows/push-and-package.yml b/.github/workflows/push.yml similarity index 60% rename from .github/workflows/push-and-package.yml rename to .github/workflows/push.yml index 20c89f68d..6f1ac429f 100644 --- a/.github/workflows/push-and-package.yml +++ b/.github/workflows/push.yml @@ -1,4 +1,4 @@ -name: Release Containers +name: Build and push images on: push: @@ -61,61 +61,9 @@ jobs: --stub-registry ${{ secrets.STUB_REGISTRY }} \ --stub-registry-path ${{ secrets.STUB_REGISTRY_BASE_PATH }} - package: - name: Package and release - needs: [build-and-push] - runs-on: ubuntu-latest - steps: - - name: Checkout - id: checkout - uses: actions/checkout@v2 - - - name: Get tag name - id: get_tag_name - run: echo "::set-output name=tag::$(echo "${{ github.ref }}" | grep -oP 'refs/tags/\K(.+)')" - - - name: Package - id: package - run: | - set -e - yarn install - build/vscdc pack --prep-and-package-only \ - --release ${{ steps.get_tag_name.outputs.tag }} \ - --github-repo ${{ github.repository }} \ - --registry ${{ secrets.REGISTRY }} \ - --registry-path ${{ secrets.REGISTRY_BASE_PATH }} \ - --stub-registry ${{ secrets.STUB_REGISTRY }} \ - --stub-registry-path ${{ secrets.STUB_REGISTRY_BASE_PATH }} - - # Set an output with the resulting package name for upload - PKG_PREFIX=$(node -p "require('./package.json').name") - echo "::set-output name=package_name::$(ls $PKG_PREFIX-*.tgz)" - - - name: Create release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ steps.get_tag_name.outputs.tag }} - release_name: ${{ steps.get_tag_name.outputs.tag }} - draft: false - prerelease: false - - - name: Upload package as release asset - id: upload_release_asset - uses: actions/upload-release-asset@v1.0.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./${{ steps.package.outputs.package_name }} - asset_name: ${{ steps.package.outputs.package_name }} - asset_content_type: application/gzip - image-info: name: Trigger info extraction - needs: [package] + needs: [build-and-push] runs-on: ubuntu-latest steps: - name: Get tag name diff --git a/.github/workflows/smoke-alpine.yaml b/.github/workflows/smoke-alpine.yaml index ea39ac6ee..c72c9246e 100644 --- a/.github/workflows/smoke-alpine.yaml +++ b/.github/workflows/smoke-alpine.yaml @@ -26,5 +26,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: alpine - image: mcr.microsoft.com/devcontainers/base:dev-alpine - user: vscode diff --git a/.github/workflows/smoke-anaconda.yaml b/.github/workflows/smoke-anaconda.yaml index 491bb5fc1..0b42f5446 100644 --- a/.github/workflows/smoke-anaconda.yaml +++ b/.github/workflows/smoke-anaconda.yaml @@ -28,5 +28,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: anaconda - image: mcr.microsoft.com/devcontainers/anaconda:dev-3 - user: vscode diff --git a/.github/workflows/smoke-codespaces.yaml b/.github/workflows/smoke-codespaces.yaml index 3c00186a9..a63a1de45 100644 --- a/.github/workflows/smoke-codespaces.yaml +++ b/.github/workflows/smoke-codespaces.yaml @@ -28,5 +28,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: codespaces - image: mcr.microsoft.com/devcontainers/universal:dev-linux - user: codespace diff --git a/.github/workflows/smoke-cpp.yaml b/.github/workflows/smoke-cpp.yaml index b434a6017..42562d67c 100644 --- a/.github/workflows/smoke-cpp.yaml +++ b/.github/workflows/smoke-cpp.yaml @@ -26,5 +26,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: cpp - image: mcr.microsoft.com/devcontainers/cpp:dev-debian - user: vscode diff --git a/.github/workflows/smoke-debian.yaml b/.github/workflows/smoke-debian.yaml index b69e99639..8254fd6fb 100644 --- a/.github/workflows/smoke-debian.yaml +++ b/.github/workflows/smoke-debian.yaml @@ -26,5 +26,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: debian - image: mcr.microsoft.com/devcontainers/base:dev-debian - user: vscode diff --git a/.github/workflows/smoke-dotnet.yaml b/.github/workflows/smoke-dotnet.yaml index 9ac3a05c0..8c1ecdb31 100644 --- a/.github/workflows/smoke-dotnet.yaml +++ b/.github/workflows/smoke-dotnet.yaml @@ -28,5 +28,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: dotnet - image: mcr.microsoft.com/devcontainers/dotnet:dev-6.0 - user: vscode diff --git a/.github/workflows/smoke-go.yaml b/.github/workflows/smoke-go.yaml index b4e227c25..728c92da7 100644 --- a/.github/workflows/smoke-go.yaml +++ b/.github/workflows/smoke-go.yaml @@ -28,5 +28,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: go - image: mcr.microsoft.com/devcontainers/go:dev-1 - user: vscode diff --git a/.github/workflows/smoke-java.yaml b/.github/workflows/smoke-java.yaml index 0d7af8d8a..64787e80b 100644 --- a/.github/workflows/smoke-java.yaml +++ b/.github/workflows/smoke-java.yaml @@ -28,5 +28,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: java - image: mcr.microsoft.com/devcontainers/java:dev-17 - user: vscode diff --git a/.github/workflows/smoke-jekyll.yaml b/.github/workflows/smoke-jekyll.yaml index 2221ccff2..43ad2cf5a 100644 --- a/.github/workflows/smoke-jekyll.yaml +++ b/.github/workflows/smoke-jekyll.yaml @@ -26,5 +26,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: jekyll - image: mcr.microsoft.com/devcontainers/jekyll:dev-bullseye - user: vscode diff --git a/.github/workflows/smoke-miniconda.yaml b/.github/workflows/smoke-miniconda.yaml index 223067e9b..56c8c154e 100644 --- a/.github/workflows/smoke-miniconda.yaml +++ b/.github/workflows/smoke-miniconda.yaml @@ -28,5 +28,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: miniconda - image: mcr.microsoft.com/devcontainers/miniconda:dev-3 - user: vscode diff --git a/.github/workflows/smoke-php.yaml b/.github/workflows/smoke-php.yaml index 6c07d9499..1e8926044 100644 --- a/.github/workflows/smoke-php.yaml +++ b/.github/workflows/smoke-php.yaml @@ -28,5 +28,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: php - image: mcr.microsoft.com/devcontainers/php:dev-8 - user: vscode diff --git a/.github/workflows/smoke-python.yaml b/.github/workflows/smoke-python.yaml index f0b46b277..36b0d9df6 100644 --- a/.github/workflows/smoke-python.yaml +++ b/.github/workflows/smoke-python.yaml @@ -28,5 +28,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: python - image: mcr.microsoft.com/devcontainers/python:dev-3 - user: vscode diff --git a/.github/workflows/smoke-ruby.yaml b/.github/workflows/smoke-ruby.yaml index ba739e916..1a8a09418 100644 --- a/.github/workflows/smoke-ruby.yaml +++ b/.github/workflows/smoke-ruby.yaml @@ -28,5 +28,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: ruby - image: mcr.microsoft.com/devcontainers/ruby:dev-3 - user: vscode diff --git a/.github/workflows/smoke-rust.yaml b/.github/workflows/smoke-rust.yaml index 2a16e299d..34d292de9 100644 --- a/.github/workflows/smoke-rust.yaml +++ b/.github/workflows/smoke-rust.yaml @@ -28,5 +28,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: rust - image: mcr.microsoft.com/devcontainers/rust:dev-bullseye - user: vscode diff --git a/.github/workflows/smoke-ubuntu.yaml b/.github/workflows/smoke-ubuntu.yaml index 731d439cb..b6e3d328a 100644 --- a/.github/workflows/smoke-ubuntu.yaml +++ b/.github/workflows/smoke-ubuntu.yaml @@ -28,5 +28,3 @@ jobs: uses: ./.github/actions/smoke-test with: definition: ubuntu - image: mcr.microsoft.com/devcontainers/base:dev-ubuntu - user: vscode diff --git a/package.json b/package.json index 87c7f22af..4435cc89e 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,5 @@ { - "name": "dev-containers", - "version": "0.0.1", - "description": "Dev Containers: Definitions", - "repository": { - "type": "git", - "url": "https://github.com/devcontainers/images.git" - }, - "author": "Microsoft Corporation", - "license": "SEE LICENSE IN LICENSE.md", - "files": [ + "files": [ "src" ], "devDependencies": { diff --git a/src/codespaces/local-features/jekyll/install.sh b/src/codespaces/local-features/jekyll/install.sh index 802f353a1..16684e12b 100644 --- a/src/codespaces/local-features/jekyll/install.sh +++ b/src/codespaces/local-features/jekyll/install.sh @@ -10,12 +10,13 @@ USERNAME=${2:-"codespace"} set -e # Use sudo to run as non-root user is not already running -sudoUserIf() { - if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then - sudo -u ${USERNAME} "$@" - else - "$@" - fi +sudo_if() { + COMMAND="$*" + if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then + su - "$USERNAME" -c "$COMMAND" + else + "$COMMAND" + fi } # If we don't yet have Ruby installed, exit. @@ -28,10 +29,8 @@ fi if ! jekyll --version > /dev/null; then echo "Installing Jekyll..." if [ "${VERSION}" = "latest" ]; then - gem install jekyll + sudo_if gem install jekyll else - gem install jekyll -v "${VERSION}" + sudo_if gem install jekyll -v "${VERSION}" fi fi - -chown -R "${USERNAME}:rvm" /usr/local/rvm/*