diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..f5f053d --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,8 @@ +ARG VARIANT=focal +FROM mcr.microsoft.com/vscode/devcontainers/base:${VARIANT} + +RUN useradd -ms /bin/bash mock-container +RUN useradd -ms /bin/bash mock-remote + +# Add a pre-existing ~/.docker folder so we can verify the fix for https://github.com/github/codespaces/issues/7185 +RUN mkdir /home/mock-remote/.docker diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 80777e0..c3b9997 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,9 +1,26 @@ { - "image": "mcr.microsoft.com/vscode/devcontainers/base:ubuntu", - "initializeCommand": "touch heythere.txt", - "containerEnv": { + "build": { + "dockerfile": "Dockerfile", + "args": { + "VARIANT": "focal" + } + }, + "initializeCommand": "touch heythere.txt && printenv > myenv.txt", + "containerEnv": { "MY_LOCAL_HOME": "${localEnv:HOME}", "A_SIMPLE_KEY": "A_SIMPLE_VALUE" }, - "postCreateCommand": "bash ./run-me.sh" + "remoteEnv": { + "PATH": "/test/path:${containerEnv:PATH}", + "TEST_REMOTE_ENV": "test" + }, + "remoteUser": "mock-remote", + "containerUser": "mock-container", + "onCreateCommand": "echo onCreate && sleep 2 && echo $USER > USER.txt", + "updateContentCommand": "echo updateContent && sleep 2 && echo finishedUpdateContent", + "waitFor": "onCreateCommand", + "postCreateCommand": "echo `whoami`> whoami.txt && bash ./run-me.sh", + "postAttachCommand": "echo postAttach >> postAttach.txt", + "workspaceFolder": "/app", + "workspaceMount" : "source=${localWorkspaceFolder},target=/app,type=bind,consistency=cached" } diff --git a/grpc-client/client.py b/grpc-client/client.py new file mode 100644 index 0000000..a0462d1 --- /dev/null +++ b/grpc-client/client.py @@ -0,0 +1,12 @@ +import grpc +import proto_pb2 +import proto_pb2_grpc + +print("Starting client and sending request...") + +with grpc.insecure_channel('unix:///workspaces/.codespaces/shared/cs-agent.sock') as channel: + stub = proto_pb2_grpc.CodespaceHostStub(channel) + metadata = (('Authorization', 'Bearer token')) + response = stub.ExportLogsAsync(proto_pb2.ExportLogsRequest(), metadata=(('authorization','Bearer token'),)) + +print("Logs file path: " + response.FilePath) \ No newline at end of file diff --git a/grpc-client/install_dependencies.sh b/grpc-client/install_dependencies.sh new file mode 100755 index 0000000..13b09cd --- /dev/null +++ b/grpc-client/install_dependencies.sh @@ -0,0 +1,3 @@ +apt update +apt install -y python3-pip +pip3 install grpcio==1.56.2 grpcio-tools==1.56.2 diff --git a/grpc-client/proto_pb2.py b/grpc-client/proto_pb2.py new file mode 100644 index 0000000..5768dce --- /dev/null +++ b/grpc-client/proto_pb2.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: proto.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0bproto.proto\x12\'Codespaces.Grpc.CodespaceHostService.v1\"\x13\n\x11\x45xportLogsRequest\"&\n\x12\x45xportLogsResponse\x12\x10\n\x08\x46ilePath\x18\x01 \x01(\t2\x9c\x01\n\rCodespaceHost\x12\x8a\x01\n\x0f\x45xportLogsAsync\x12:.Codespaces.Grpc.CodespaceHostService.v1.ExportLogsRequest\x1a;.Codespaces.Grpc.CodespaceHostService.v1.ExportLogsResponseb\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'proto_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + _EXPORTLOGSREQUEST._serialized_start=56 + _EXPORTLOGSREQUEST._serialized_end=75 + _EXPORTLOGSRESPONSE._serialized_start=77 + _EXPORTLOGSRESPONSE._serialized_end=115 + _CODESPACEHOST._serialized_start=118 + _CODESPACEHOST._serialized_end=274 +# @@protoc_insertion_point(module_scope) diff --git a/grpc-client/proto_pb2.pyi b/grpc-client/proto_pb2.pyi new file mode 100644 index 0000000..de5ece5 --- /dev/null +++ b/grpc-client/proto_pb2.pyi @@ -0,0 +1,15 @@ +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from typing import ClassVar as _ClassVar, Optional as _Optional + +DESCRIPTOR: _descriptor.FileDescriptor + +class ExportLogsRequest(_message.Message): + __slots__ = [] + def __init__(self) -> None: ... + +class ExportLogsResponse(_message.Message): + __slots__ = ["FilePath"] + FILEPATH_FIELD_NUMBER: _ClassVar[int] + FilePath: str + def __init__(self, FilePath: _Optional[str] = ...) -> None: ... diff --git a/grpc-client/proto_pb2_grpc.py b/grpc-client/proto_pb2_grpc.py new file mode 100644 index 0000000..56a3ca5 --- /dev/null +++ b/grpc-client/proto_pb2_grpc.py @@ -0,0 +1,66 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + +import proto_pb2 as proto__pb2 + + +class CodespaceHostStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.ExportLogsAsync = channel.unary_unary( + '/Codespaces.Grpc.CodespaceHostService.v1.CodespaceHost/ExportLogsAsync', + request_serializer=proto__pb2.ExportLogsRequest.SerializeToString, + response_deserializer=proto__pb2.ExportLogsResponse.FromString, + ) + + +class CodespaceHostServicer(object): + """Missing associated documentation comment in .proto file.""" + + def ExportLogsAsync(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_CodespaceHostServicer_to_server(servicer, server): + rpc_method_handlers = { + 'ExportLogsAsync': grpc.unary_unary_rpc_method_handler( + servicer.ExportLogsAsync, + request_deserializer=proto__pb2.ExportLogsRequest.FromString, + response_serializer=proto__pb2.ExportLogsResponse.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'Codespaces.Grpc.CodespaceHostService.v1.CodespaceHost', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + + + # This class is part of an EXPERIMENTAL API. +class CodespaceHost(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def ExportLogsAsync(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/Codespaces.Grpc.CodespaceHostService.v1.CodespaceHost/ExportLogsAsync', + proto__pb2.ExportLogsRequest.SerializeToString, + proto__pb2.ExportLogsResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/run-me.sh b/run-me.sh index 908f5a3..cc0ef10 100644 --- a/run-me.sh +++ b/run-me.sh @@ -1,3 +1,5 @@ #!/bin/bash echo -n "I was triggered by the postcreate" >> ./postcreated.txt +git add ./postcreated.txt +git commit -m "I am a git commit" # Don't remove, this will break the GitStatusAsserts!