Skip to content

DevContainer PostCreateCommand is not consistent with VSCode #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hinate13 opened this issue May 31, 2025 · 0 comments
Open

DevContainer PostCreateCommand is not consistent with VSCode #375

hinate13 opened this issue May 31, 2025 · 0 comments

Comments

@hinate13
Copy link

hinate13 commented May 31, 2025

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/[email protected]
      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/[email protected]
      with:    
        push: never
        runCmd: python3 special_add.py
    # ...existing code...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant