Skip to content
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

Add development environment using dev container #90

Merged
merged 15 commits into from
Sep 5, 2023

Conversation

R-HNF
Copy link
Contributor

@R-HNF R-HNF commented Aug 3, 2023

Description

Changes

  • Add Dockerfile.dev and devcontainer.json to use dev container on Visual Studio Code.
  • Modified the Dockerfile to not be fixed to amd64.
    • I have verified the test in the arm environment using the development container on my M2 Mac and Intel Windows.
  • There are some small changes.

Future plans

  • Prepare the document that describes how to develop GatlingOperator using a dev container.
  • Utilize utilize buildx for creating builds that support multiple platforms.

References

Notes

  • I'm using keychain to forward the ssh-agent from my Mac to a dev container.
  • Using Rosetta for amd emulation can result in slower processing, causing kube-apiserver to fail to start, and tests may not pass.
  • You can use dev container without VSCode.
    # 1. Build the container image.
    $ docker build -f Dockerfile.dev -t gatling-operator-dev-container .
    # 2. Create and login an dev container
    $ docker run \
        --name=gatling-operator-dev-container  \
        --hostname=gatling-operator-dev-container \
        --network=host \
        --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
        --mount type=bind,src=.,dst=/workspace \
        --env IN_DEV_CONTAINER="true" \
        -ti gatling-operator-dev-container
    # 3. If you exited, login to dev container again.
    $ docker exec -ti gatling-operator-dev-container bash
    

Checklist

  • Tests have been added (if applicable, ie. when operator codes are added or modified)
  • Relevant docs have been added or modified (if applicable, ie. when new features are added or current features are modified)

Relevant issue #88

@R-HNF R-HNF changed the title Add docker dev env Add development environment using dev container Aug 3, 2023
@R-HNF R-HNF marked this pull request as ready for review August 3, 2023 06:42
@R-HNF R-HNF requested review from gold-kou and itiB August 3, 2023 06:43
@R-HNF R-HNF added the enhancement New feature or request label Aug 3, 2023
@R-HNF R-HNF requested a review from a team August 3, 2023 07:03
Copy link
Contributor

@gold-kou gold-kou left a comment

Choose a reason for hiding this comment

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

I checked that some make commands work correctly.

LGTM

Makefile Outdated
Comment on lines 53 to 56
@echo "Creating Cluster"
kind create cluster --name ${KIND_CLUSTER_NAME} --image=kindest/node:${K8S_NODE_IMAGE} --config ${KIND_CONFIG_DIR}/cluster.yaml
cp -r ${HOME}/.kube .
endif
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no problem with cp command running in the dev container, but I'm not happy if it runs locally.
Can you make if depending on whether it's in the dev container?

i think, dev container can set some environment variables from devcontainer.json.
ex. Create some check variable like IN_DEV_CONTAINER and check it.
https://code.visualstudio.com/remote/advancedcontainers/environment-variables

Copy link
Contributor Author

@R-HNF R-HNF Aug 24, 2023

Choose a reason for hiding this comment

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

@itiB
I added IN_DEV_CONTAINER to check whether it's in the dev container.
Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cp command creates a .kube directory under the existing .kube directory, so I changed it to use kind get kubeconfig.

Copy link
Contributor

@itiB itiB left a comment

Choose a reason for hiding this comment

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

Looks well:+1:
I make some suggestion comment.

"--name=gatling-operator-dev-container",
"--hostname=gatling-operator-dev-container",
// Set network mode to host to communicate with other containers.
"--network=host"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's necessary to control kind clusters on the host.

"IN_DEV_CONTAINER": "true"
},
// Restore the local kubectl config to a dev container.
"postStartCommand": "if [ -d ${containerWorkspaceFolder}/.kube ]; then cp -r ${containerWorkspaceFolder}/.kube $HOME/.kube; fi",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

restoring the backed-up kubeconfig.

@@ -16,7 +16,7 @@ COPY controllers/ controllers/
COPY pkg/ pkg/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$(dpkg --print-architecture) go build -a -o manager main.go
Copy link
Contributor Author

Choose a reason for hiding this comment

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

make it available for use in other architectures as well.

@R-HNF
Copy link
Contributor Author

R-HNF commented Aug 24, 2023

@itiB
Please confirm that I have added how to use the dev container without using VSCode. Thanks:+1:

@R-HNF R-HNF requested a review from itiB August 24, 2023 10:59
@R-HNF R-HNF merged commit 17bfcfd into st-tech:main Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants