Skip to content

Conversation

@Sozhan308
Copy link
Contributor

@Sozhan308 Sozhan308 commented Feb 6, 2025

Add Development Container Configuration (#54)

Overview

This PR introduces devcontainer setup configurations. The configuration includes necessary tools, dependencies, and post-setup scripts for Go and Node.js development.

Changes

Added Development Container Config Files

  • Dockerfile : Sets up Ubuntu-based development environment with:

    • Go development tools
    • Node.js and npm
    • Google Cloud SDK and kubectl
    • User permissions and workspace setup
  • docker-compose.yml : Configures:

    • Volume mounts for source code and caches
    • Build arguments and environment variables
    • Docker socket access for container operations
    • Network and security settings
  • setup-dev.sh : Post-creation setup script that:

    • Verifies required tool installations
    • Sets up Go development environment
    • Configures npm and Angular CLI
    • Sets Git configurations

Testing

Verified the following tools inside the devcontainer

go version
node --version
npm --version
ng --version
gcloud --version
kubectl version --client

devcontainer

Notes

  • Requires Docker and Docker Compose
  • Initial container build may take 3-4 minutes

@Sozhan308 Sozhan308 force-pushed the setup-devcontainer-configuration-#54 branch from 86a1f24 to f53db3b Compare February 6, 2025 19:37
…rm#54)

- Add Dockerfile with Go and Node.js development environment
- Configure docker-compose.yml with volume mounts and caching
- Create setup-dev.sh for post-container initialization
- Set up Git, Go, and Node.js development tools
- Add environment variables and user configurations
- Configure npm global package handling
- Implement tool verification and error handling

This change introduces containerized development environment
for consistent development across different machines.
…m#54)

- Add quick start instructions for VS Code and other IDEs
- Include container verification steps
@Sozhan308 Sozhan308 force-pushed the setup-devcontainer-configuration-#54 branch from f53db3b to 6e3cae9 Compare February 6, 2025 19:54
Copy link
Member

@kyasbal kyasbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing our code base!

I haven't tried around .devcontainer for a while, but I learnt how this is well configured and make new contributors easy to start contributes. I think @RyuSA will also comment on this because he should be familiar with around this.

I added some comments. We are open to improve, thus please feel free to reply these suggestions if you have better solution rather than my suggestion.

Thanks! 👍

@kyasbal
Copy link
Member

kyasbal commented Feb 7, 2025

And we need to add a license headers in the following scripts.

.devcontainer/docker-compose.yml
.devcontainer/DockerFile
.devcontainer/setup-dev.sh
.devcontainer/setup-check.sh

You can add this just by running make add-licenses
Ref:

add-licenses:
$(GOPATH)/bin/addlicense -c "Google LLC" -l apache .

@kyasbal kyasbal requested a review from RyuSA February 7, 2025 01:27
…oogleCloudPlatform#54)

- Add hash verification for tool installations
- Support AMD64/ARM64 architectures for Node.js
- Fix npm global permissions and caching
- Improve build configuration and cleanup
@Sozhan308 Sozhan308 force-pushed the setup-devcontainer-configuration-#54 branch from 90b5e6b to e9911cf Compare February 8, 2025 19:52
Copy link
Member

@kyasbal kyasbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it on my newly setup Linux VM. It worked after configuring user id or group id environment variables as I pointed out in a review comment.

This devcontainer is very easy setup and so useful!

Comment on lines 35 to 36
USER_UID: ${USER_UID:-1000}
USER_GID: ${USER_GID:-1000}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how these are common to have in environment variables.
I tested this with a new Debian environment just with a docker command. $USER_UID and $USER_GID don't exist but $USERNAME exists.

This seems to cause file permission error on setup-dev.sh L25 because these folder is hold by UID 1000, but VSCode seems to pass the right UID to connect the container.
It works if I set these outside of the container and we can document it, but do you have any better solution?

Copy link
Contributor Author

@Sozhan308 Sozhan308 Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, I've introduced a different approach 7df77f0 for the user handling to work better across different environments:

  1. Made the GID allocation dynamic:
    • Uses next available GID incase of system group conflicts (like GID 20 for 'dialout')
    • Preserves specified GID when no conflicts exist
  2. User setup is now more robust:
    • Used POSIX-standard id command for detection and UID/GID fallbacks in Dockerfile (UID/GID 1000)
    • Should ideally work with VSCode and other environments

I have tested and it's working. Let me know your thoughts on this!

NOTE: This must be run as a non-root user. Running as root (UID 0) is not supported and will fail with an error.

…dPlatform#54)

- Add support for large UIDs in container user creation
- Fix user group handling when GID conflicts with system groups
- Update environment variable management in setup script
@Sozhan308 Sozhan308 force-pushed the setup-devcontainer-configuration-#54 branch from c1a6a47 to 7df77f0 Compare February 9, 2025 09:25
Copy link
Member

@kyasbal kyasbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks everything good except a thing.
The .env generated in .devcontainer after the build seems not to be ignored in .gitignore.

If I understand this change correctly, that should be ignored, shouldn't it? I'm gonna approve this PR once this concern is solved.

@Sozhan308
Copy link
Contributor Author

Looks everything good except a thing. The .env generated in .devcontainer after the build seems not to be ignored in .gitignore.

If I understand this change correctly, that should be ignored, shouldn't it? I'm gonna approve this PR once this concern is solved.

Yep, 👍 I'll add it

Copy link
Member

@kyasbal kyasbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome! Thank you a lot for your contribution 🎉 🎉 🎉

@kyasbal kyasbal merged commit 0dbe123 into GoogleCloudPlatform:main Feb 10, 2025
6 checks passed
@kyasbal kyasbal linked an issue Feb 10, 2025 that may be closed by this pull request
@kyasbal kyasbal mentioned this pull request Feb 10, 2025
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

Successfully merging this pull request may close these issues.

Setup .devcontainer

2 participants