-
Notifications
You must be signed in to change notification settings - Fork 4
Containerise dependencies required to run tasks in dev workflow #53
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
Changes from 17 commits
6fe352f
48d112b
b26044d
2ef4633
dac6b1f
dfe10c3
30c6a4c
3e5c1cd
30b7781
e26440e
0e669a9
0da51be
a75abac
e77f4f0
68ecc8d
cdcc991
a05d485
c8566f2
b823872
4e7619e
6649ed7
cba7c04
5b4b5aa
3c23789
1226492
629cb1e
0825b3e
8889f47
83c1dc0
4de1ef6
a3ef59e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # Base image for all shared Containerfiles for taskfiles | ||
| # Use this image as base image for app specific container files | ||
| FROM --platform=$BUILDPLATFORM ubuntu:24.04 | ||
|
|
||
| ARG TARGETOS | ||
| ARG TARGETARCH | ||
|
|
||
| WORKDIR /tools | ||
|
|
||
| # Set environment variables | ||
| ENV DEBIAN_FRONTEND=noninteractive \ | ||
| HOME=/home/devuser \ | ||
| SHELL=/bin/bash | ||
|
|
||
| # Install CLI tools | ||
| RUN apt-get update && apt-get install -y \ | ||
| curl \ | ||
| jq \ | ||
| yq \ | ||
| gnupg \ | ||
| bash-completion \ | ||
|
|
||
| # Install Helm | ||
| && curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash \ | ||
chris-sanders marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Install kubectl | ||
| && curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \ | ||
| && chmod +x kubectl \ | ||
| && mv kubectl /usr/local/bin/ \ | ||
|
|
||
| # Install Task | ||
| && sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin \ | ||
|
|
||
| # Install Helmfile | ||
| && curl -Ls $(curl -s https://api.github.com/repos/helmfile/helmfile/releases/latest \ | ||
| | grep "browser_download_url.*linux_amd64.tar.gz" \ | ||
| | cut -d : -f 2,3 \ | ||
| | tr -d \") -o helmfile.tar.gz \ | ||
| && tar xf helmfile.tar.gz helmfile && rm helmfile.tar.gz \ | ||
| && mv helmfile /usr/local/bin/helmfile \ | ||
|
|
||
| # Install Replicated CLI | ||
| && curl -Ls $(curl -s https://api.github.com/repos/replicatedhq/replicated/releases/latest \ | ||
| | grep "browser_download_url.*linux_amd64.tar.gz" \ | ||
| | cut -d : -f 2,3 \ | ||
| | tr -d \") -o replicated.tar.gz \ | ||
| && tar xf replicated.tar.gz replicated && rm replicated.tar.gz \ | ||
| && mv replicated /usr/local/bin/replicated \ | ||
|
|
||
| # Install Google Cloud CLI | ||
| && echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list \ | ||
| && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg \ | ||
| && apt-get update \ | ||
| && apt-get install google-cloud-cli -y \ | ||
|
|
||
| # Clean up | ||
| && apt-get purge -y \ | ||
| curl \ | ||
| gnupg \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Create a non-root user for better security | ||
| RUN groupadd -r devuser && useradd -r -g devuser -m -s /bin/bash devuser | ||
|
|
||
| # Copy shell completion scripts | ||
| COPY container/tool-completions.sh tool-completions.sh | ||
|
|
||
| # Copy entrypoint script | ||
| COPY container/entrypoint.sh entrypoint.sh | ||
| RUN chmod +x entrypoint.sh | ||
|
|
||
| # Set working directory | ||
| WORKDIR /workspace | ||
|
|
||
| # Switch to non-root user | ||
| USER devuser | ||
|
|
||
| # Set entrypoint | ||
| ENTRYPOINT ["/tools/entrypoint.sh", "-l"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Uncomment force_color_prompt in bashrc | ||
| sed -i 's/#force_color_prompt=yes/force_color_prompt=yes/' $HOME/.bashrc | ||
|
|
||
| # Source the tool completions | ||
| echo "source /tools/tool-completions.sh" >> $HOME/.bashrc | ||
|
|
||
| # Execute the passed command or default to bash | ||
| exec "$@" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #!/bin/bash | ||
|
|
||
| # kubectl completion | ||
| source <(kubectl completion bash) | ||
| alias k=kubectl | ||
| complete -o default -F __start_kubectl k | ||
|
|
||
| # helm completion | ||
| source <(helm completion bash) | ||
|
|
||
| # task completion | ||
| source <(task --completion bash) | ||
|
|
||
| # helmfile completion | ||
| source <(helmfile completion bash) | ||
|
|
||
| # replicated completion | ||
| source <(replicated completion bash) | ||
|
|
||
| # gcloud completion | ||
| source /usr/share/google-cloud-sdk/completion.bash.inc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| version: "3" | ||
|
|
||
| # Development environment tasks | ||
| tasks: | ||
| build-image: | ||
| desc: Build development container image | ||
| vars: | ||
| DEV_CONTAINER_TAG: '{{.DEV_CONTAINER_TAG | default "latest"}}' | ||
| CONTAINERFILE: '{{.CONTAINERFILE | default "./container/Containerfile"}}' | ||
| BUILD_ARGS: '{{.BUILD_ARGS | default ""}}' | ||
| requires: | ||
| vars: [DEV_CONTAINER_REPOSITORY, DEV_CONTAINER_IMAGE, CONTAINERFILE] | ||
|
|
||
| cmds: | ||
| - '{{.CONTAINER_RUNTIME}} build -t {{.DEV_CONTAINER_REPOSITORY}}/{{.DEV_CONTAINER_IMAGE}}:{{.DEV_CONTAINER_TAG}} -f {{.CONTAINERFILE}} .' | ||
|
|
||
| start: | ||
| desc: Start development container in background | ||
| silent: true | ||
| cmds: | ||
| - task: start-implementation | ||
|
|
||
| # Start development container in background. | ||
| # It's internal because it's used by shell and start tasks. | ||
| start-implementation: | ||
|
||
| desc: Start development container in background | ||
| silent: true | ||
| run: once | ||
| internal: true | ||
| vars: | ||
| DEV_CONTAINER_REPOSITORY: '{{.DEV_CONTAINER_REPOSITORY}}' | ||
| DEV_CONTAINER_IMAGE: '{{.DEV_CONTAINER_IMAGE}}' | ||
| DEV_CONTAINER_TAG: '{{.DEV_CONTAINER_TAG | default "latest"}}' | ||
| DEV_CONTAINER_NAME: '{{.DEV_CONTAINER_NAME}}' | ||
| requires: | ||
| vars: [DEV_CONTAINER_REPOSITORY, DEV_CONTAINER_IMAGE, DEV_CONTAINER_TAG, DEV_CONTAINER_NAME, REPLICATED_API_TOKEN] | ||
|
|
||
| status: | ||
| - '{{.CONTAINER_RUNTIME}} ps | grep -q "{{.DEV_CONTAINER_NAME}}"' | ||
| cmds: | ||
| - | | ||
| # Start container with host networking for kubectl port-forward compatibility | ||
| CONTAINER_ID=$({{.CONTAINER_RUNTIME}} run --rm --name {{.DEV_CONTAINER_NAME}} -d \ | ||
| -v $(pwd):/workspace \ | ||
| -e REPLICATED_API_TOKEN={{ .REPLICATED_API_TOKEN }} \ | ||
| {{.DEV_CONTAINER_REPOSITORY}}/{{.DEV_CONTAINER_IMAGE}}:{{.DEV_CONTAINER_TAG}} bash -c 'trap "exit 0" TERM; sleep infinity & wait') | ||
| if [ $? -eq 0 ]; then | ||
| echo "Development container started successfully with ID: $CONTAINER_ID" | ||
| else | ||
| echo "Failed to start development container" | ||
| exit 1 | ||
| fi | ||
| shell: | ||
| desc: Attach to development container shell | ||
| silent: true | ||
| requires: | ||
| vars: [DEV_CONTAINER_NAME] | ||
| deps: | ||
| - start-implementation | ||
| cmds: | ||
| - echo "Connecting to {{.DEV_CONTAINER_NAME}}..." | ||
| - '{{.CONTAINER_RUNTIME}} exec -it {{.DEV_CONTAINER_NAME}} /bin/bash' | ||
|
|
||
| stop: | ||
| desc: Stop development container | ||
| silent: true | ||
| requires: | ||
| vars: [DEV_CONTAINER_NAME] | ||
| cmds: | ||
| - | | ||
| if {{.CONTAINER_RUNTIME}} ps | grep -q "{{.DEV_CONTAINER_NAME}}"; then | ||
| echo "Stopping {{.DEV_CONTAINER_NAME}} development container..." | ||
| {{.CONTAINER_RUNTIME}} stop {{.DEV_CONTAINER_NAME}} | ||
| else | ||
| echo "Container {{.DEV_CONTAINER_NAME}} is not running" | ||
| fi | ||
| restart: | ||
| desc: Restart development container | ||
| silent: true | ||
| requires: | ||
| vars: [DEV_CONTAINER_NAME] | ||
| cmds: | ||
| - task: stop | ||
| - task: start | ||
Uh oh!
There was an error while loading. Please reload this page.