Skip to content

Commit

Permalink
Add env-vars-on-post-create tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartleeks committed Feb 22, 2023
1 parent bf5c2e5 commit e2da53e
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .azure-devops/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ jobs:
imageTag: $(IMAGE_TAG)
sourceBranchFilterForPush: ''

- job: test_env_vars_on_post_create
displayName: Test env-vars-on-post-create
steps:
- script: |
docker login -u $ACR_USERNAME -p $ACR_TOKEN $(ACR_NAME).azurecr.io
displayName: 'Log in to Azure Container Registry'
env:
ACR_NAME: $(ACR_NAME)
ACR_TOKEN: $(ACR_TOKEN)
ACR_USERNAME: $(ACR_USERNAME)
- task: DevcontainersCi@0
inputs:
imageName: '$(ACR_NAME).azurecr.io/devcontainers-ci/azdo-devcontainer-build-run/test/run-args'
subFolder: github-tests/Dockerfile/run-args
runCmd: |
cat marker.txt
cat marker.txt | grep 'post-create: TEST_ENV_VALUE=testing123'
env: |
TEST_ENV_VALUE=testing123
imageTag: $(IMAGE_TAG)
sourceBranchFilterForPush: ''


- job: test_simple
displayName: Test simple
steps:
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/ci_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ jobs:
- test-compose-features
- test-simple
- test-no-run
- test-env-vars-on-post-create
- test-platform-with-runcmd
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -475,6 +476,46 @@ jobs:
push
pull_request
test-env-vars-on-post-create:
name: Run GitHub env-vars-on-post-create test
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
# if the following value is missing (i.e. not triggered via comment workflow)
# then the default checkout will apply
ref: ${{ inputs.prRef }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
if: ${{ needs.build.outputs.image_push_option == 'filter' }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run test
uses: ./
with:
subFolder: github-tests/Dockerfile/env-vars-on-post-create
imageName: ghcr.io/devcontainers/ci/tests/env-vars-on-post-create
env: |
TEST_ENV_VALUE=testing123
runCmd: |
cat marker.txt
cat marker.txt | grep 'post-create: TEST_ENV_VALUE=testing123'
imageTag: ${{ needs.build.outputs.image_tag }}
push: ${{ needs.build.outputs.image_push_option }}
eventFilterForPush: |
push
pull_request
test-gh-build-args:
name: Run GitHub build-args test
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# [Choice] Debian / Ubuntu version: debian-10, debian-9, ubuntu-20.04, ubuntu-18.04
# See https://github.com/microsoft/vscode-dev-containers/tree/master/containers/debian
ARG VARIANT=debian-10
FROM mcr.microsoft.com/vscode/devcontainers/base:${VARIANT}


# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Set env for tracking that we're running in a devcontainer
ENV DEVCONTAINER=true

# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
# will be updated to match your local UID/GID (when using the dockerFile property).
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

USER $USERNAME
RUN \
mkdir -p ~/.local/bin \
&& echo "export PATH=\$PATH:~/.local/bin" >> ~/.bashrc

# Configure apt, install packages and general tools
RUN sudo apt-get update \
&& sudo apt-get -y install --no-install-recommends apt-utils dialog nano bash-completion sudo bsdmainutils \
#
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
&& sudo apt-get -y install git iproute2 procps lsb-release figlet build-essential

# Save command line history
RUN echo "export HISTFILE=/home/$USERNAME/commandhistory/.bash_history" >> "/home/$USERNAME/.bashrc" \
&& echo "export PROMPT_COMMAND='history -a'" >> "/home/$USERNAME/.bashrc" \
&& mkdir -p /home/$USERNAME/commandhistory \
&& touch /home/$USERNAME/commandhistory/.bash_history \
&& chown -R $USERNAME /home/$USERNAME/commandhistory

# Set env for tracking that we're running in a devcontainer
ENV DEVCONTAINER=true

# __DEVCONTAINER_SNIPPET_INSERT__ (control where snippets get inserted using the devcontainer CLI)

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.117.1/containers/go
{
"name": "env-vars-on-post-create",
"dockerFile": "Dockerfile",
"build": {
"cacheFrom": "ghcr.io/devcontainers/ci/tests/run-args:latest"
},


"runArgs": [
"--hostname", "my-host"
],

"mounts": [
// Keep command history
"source=build-args-bashhistory,target=/home/vscode/commandhistory",

],
"remoteEnv": {
"TEST_ENV_VALUE": "${localEnv:TEST_ENV_VALUE}"
},

// Add the IDs of extensions you want installed when the container is created.
// "extensions": [],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "./post-create.sh",

"remoteUser": "vscode"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e

echo "post-create: TEST_ENV_VALUE=${TEST_ENV_VALUE}" >> marker.txt

0 comments on commit e2da53e

Please sign in to comment.