Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/devcontainers/images into s…
Browse files Browse the repository at this point in the history
…amruddhikhandale/cleanup
  • Loading branch information
samruddhikhandale authored Jun 20, 2022
2 parents 8bf0a6e + 1eb14ca commit 4371569
Show file tree
Hide file tree
Showing 22 changed files with 28 additions and 213 deletions.
10 changes: 1 addition & 9 deletions .github/actions/smoke-test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
27 changes: 9 additions & 18 deletions .github/actions/smoke-test/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
47 changes: 5 additions & 42 deletions .github/actions/smoke-test/test.sh
Original file line number Diff line number Diff line change
@@ -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}
docker stop $(docker container ls -q)
41 changes: 1 addition & 40 deletions .github/workflows/push-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release Containers
name: Build and push images

on:
push:
Expand Down Expand Up @@ -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/[email protected]
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
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/smoke-alpine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: alpine
image: mcr.microsoft.com/devcontainers/base:dev-alpine
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-anaconda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: anaconda
image: mcr.microsoft.com/devcontainers/anaconda:dev-3
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-codespaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: codespaces
image: mcr.microsoft.com/devcontainers/universal:dev-linux
user: codespace
2 changes: 0 additions & 2 deletions .github/workflows/smoke-cpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: cpp
image: mcr.microsoft.com/devcontainers/cpp:dev-debian
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-debian.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: debian
image: mcr.microsoft.com/devcontainers/base:dev-debian
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-dotnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: dotnet
image: mcr.microsoft.com/devcontainers/dotnet:dev-6.0
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: go
image: mcr.microsoft.com/devcontainers/go:dev-1
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-java.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: java
image: mcr.microsoft.com/devcontainers/java:dev-17
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-jekyll.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: jekyll
image: mcr.microsoft.com/devcontainers/jekyll:dev-bullseye
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-miniconda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: miniconda
image: mcr.microsoft.com/devcontainers/miniconda:dev-3
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-php.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: php
image: mcr.microsoft.com/devcontainers/php:dev-8
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: python
image: mcr.microsoft.com/devcontainers/python:dev-3
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-ruby.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: ruby
image: mcr.microsoft.com/devcontainers/ruby:dev-3
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: rust
image: mcr.microsoft.com/devcontainers/rust:dev-bullseye
user: vscode
2 changes: 0 additions & 2 deletions .github/workflows/smoke-ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ jobs:
uses: ./.github/actions/smoke-test
with:
definition: ubuntu
image: mcr.microsoft.com/devcontainers/base:dev-ubuntu
user: vscode
11 changes: 1 addition & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
19 changes: 9 additions & 10 deletions src/codespaces/local-features/jekyll/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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/*

0 comments on commit 4371569

Please sign in to comment.