Skip to content

DevContainer PostCreateCommand is not consistent with VSCode #375

Description

@hangryBytes

I'm trying to setup a barebone simple devContainer for use with VSCode on Windows 11 and also GitHub runner. I'm running into what seems like an obvious roadblock to make this happen. I was hoping the GitHub CLI would find the sh file to execute, but it's not searching from the right path. Any help to clarify the failure appreciated!

Here's my .devcontainer/devcontainer.json:

{
    "name": "Test CI/CD Project",
    "build": { 
        "dockerfile": "Dockerfile"
    },
    "features": {
        "ghcr.io/devcontainers/features/git:1": {
            "version": "latest"
        }
    },
    "postCreateCommand": "chmod +x scripts/*.sh && scripts/post-create.sh",
    "postStartCommand": "chmod +x scripts/*.sh && scripts/post-start.sh",
    "customizations": {
        "vscode": {
            "extensions": [
                "ms-azuretools.vscode-docker"
            ],
            "settings": {
                "terminal.integrated.defaultProfile.linux": "bash"
            }
        }
    },
    "remoteUser": "root",
    "forwardPorts": []
}

Here's .devContainer/scripts/post-create.sh:


#!/bin/bash

# This script runs after the container is created
echo 'Post-create script running (/.devcontainer/scripts)...'
echo "Current folder: $(pwd)"
echo "Current user: $(whoami)"

I also added /scripts/post-create.sh (note the difference in first echo showing identifying which script runs):

#!/bin/bash

# This script runs after the container is created
echo 'Post-create script running from (/workspace/scripts)...'
echo "Current folder: $(pwd)"
echo "Current user: $(whoami)"

Expectation: This build works in VSCode, and it prints

'Post-create script running (/.devcontainer/scripts)...'

However, when run from github runner, it will show:

Post-create script running from (/workspace/scripts)

See logs logs.txt

Here's my github workflow:

name: Test CI/CD with DevContainer Builder

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  test-custom-builder:
    runs-on: ubuntu-latest
    
    # Add permissions for pushing to GitHub Container Registry
    permissions:
      contents: read
      packages: write
    
    steps:    
    - name: Checkout code
      uses: actions/checkout@v3

    # Add authentication step for GitHub Container Registry
    - name: Log in to GitHub Container Registry
      uses: docker/login-action@v2
      with:
        registry: ghcr.io
        username: ${{ github.actor }}
        password: ${{ secrets.GITHUB_TOKEN }}

    - name: Pre-build dev container image
      uses: devcontainers/ci@v0.3
      with:
        imageName: ghcr.io/${{ github.repository }}/devcontainer
        # cacheFrom: ghcr.io/${{ github.repository }}/devcontainer
        # push: always    

    - name: Run make ci-build in dev container
      uses: devcontainers/ci@v0.3
      with:    
        push: never
        runCmd: python3 special_add.py
    # ...existing code...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions