-
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 12 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 |
|---|---|---|
|
|
@@ -2,31 +2,36 @@ version: "3" | |
|
|
||
| includes: | ||
| utils: ./taskfiles/utils.yml | ||
| dev: ./taskfiles/container.yml | ||
|
|
||
| vars: | ||
| # Application configuration | ||
| APP_NAME: '{{.REPLICATED_APP | default "wg-easy"}}' | ||
|
|
||
| # Cluster configuration | ||
| CLUSTER_NAME: '{{.CLUSTER_NAME | default "test-cluster"}}' | ||
| K8S_VERSION: '{{.K8S_VERSION | default "1.32.2"}}' | ||
| DISK_SIZE: '{{.DISK_SIZE | default "100"}}' | ||
| INSTANCE_TYPE: '{{.INSTANCE_TYPE | default "r1.small"}}' | ||
| DISTRIBUTION: '{{.DISTRIBUTION | default "k3s"}}' | ||
| KUBECONFIG_FILE: './{{.CLUSTER_NAME}}.kubeconfig' | ||
|
|
||
| # Ports configuration | ||
| EXPOSE_PORTS: | ||
| - port: 30443 | ||
| protocol: https | ||
| - port: 30080 | ||
| protocol: http | ||
|
|
||
| # GCP default configuration | ||
| GCP_PROJECT: '{{.GCP_PROJECT | default "replicated-qa"}}' | ||
| GCP_ZONE: '{{.GCP_ZONE | default "us-central1-a"}}' | ||
| VM_NAME: '{{.VM_NAME | default (printf "%s-dev" (or (env "GUSER") "user"))}}' | ||
|
|
||
| # Docker workflow configuration | ||
| IMAGE_NAME: ttl.sh/wg-easy-dev | ||
|
||
| CONTAINER_NAME: wg-easy-dev | ||
chris-sanders marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| tasks: | ||
| default: | ||
| desc: Show available tasks | ||
|
|
@@ -91,7 +96,7 @@ tasks: | |
| echo "Removing old kubeconfig file" | ||
| rm -f {{.KUBECONFIG_FILE}} | ||
| fi | ||
| fi | ||
| fi | ||
|
|
||
| setup-kubeconfig: | ||
| desc: Get kubeconfig and prepare cluster for application deployment | ||
|
|
@@ -112,7 +117,7 @@ tasks: | |
| true | ||
| fi | ||
| deps: | ||
| - create-cluster | ||
| - cluster-create | ||
| - verify-kubeconfig | ||
|
|
||
| dependencies-update: | ||
|
|
@@ -138,7 +143,7 @@ tasks: | |
| if [ -z "$CLUSTER_ID" ]; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if all ports are already exposed | ||
| expected_count={{len .EXPOSE_PORTS}} | ||
| port_checks="" | ||
|
|
@@ -147,7 +152,7 @@ tasks: | |
| {{end}} | ||
| # Remove trailing "or " | ||
| port_checks="${port_checks% or }" | ||
|
|
||
| PORT_COUNT=$(replicated cluster port ls $CLUSTER_ID --output json | jq -r ".[] | select($port_checks) | .upstream_port" | wc -l | tr -d ' ') | ||
| [ "$PORT_COUNT" -eq "$expected_count" ] | ||
| cmds: | ||
|
|
@@ -169,10 +174,10 @@ tasks: | |
| echo "Error: Could not find cluster with name {{.CLUSTER_NAME}}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Get exposed URLs | ||
| ENV_VARS=$(task utils:port-operations OPERATION=getenv CLUSTER_NAME={{.CLUSTER_NAME}}) | ||
|
|
||
| # Deploy with helmfile | ||
| echo "Using $ENV_VARS" | ||
| eval "KUBECONFIG={{.KUBECONFIG_FILE}} $ENV_VARS helmfile sync --wait" | ||
|
|
@@ -193,7 +198,7 @@ tasks: | |
| echo "No clusters found with name {{.CLUSTER_NAME}}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| for id in $CLUSTER_IDS; do | ||
| echo "Deleting cluster ID: $id" | ||
| replicated cluster rm "$id" | ||
|
|
@@ -213,7 +218,7 @@ tasks: | |
| - echo "Preparing release files..." | ||
| - rm -rf ./release | ||
| - mkdir -p ./release | ||
|
|
||
| # Copy all non-config.yaml files | ||
| - echo "Copying non-config YAML files to release folder..." | ||
| - find . -path '*/replicated/*.yaml' -not -name 'config.yaml' -exec cp {} ./release/ \; | ||
|
|
@@ -237,27 +242,27 @@ tasks: | |
| yq '.spec.chart.chartVersion = strenv(version) | .spec.chart.chartVersion style="single"' $directory/$helmChartName | tee release/$helmChartName | ||
|
|
||
| done < <(find . -maxdepth 2 -mindepth 2 -type d -name replicated) | ||
|
|
||
| # Merge config.yaml files | ||
| - echo "Merging config.yaml files..." | ||
| - | | ||
| # Start with an empty config file | ||
| echo "{}" > ./release/config.yaml | ||
|
|
||
| # Merge all app config.yaml files first (excluding root replicated) | ||
| for config_file in $(find . -path '*/replicated/config.yaml' | grep -v "^./replicated/"); do | ||
| echo "Merging $config_file..." | ||
| yq eval-all '. as $item ireduce ({}; . * $item)' ./release/config.yaml "$config_file" > ./release/config.yaml.new | ||
| mv ./release/config.yaml.new ./release/config.yaml | ||
| done | ||
|
|
||
| # Merge root config.yaml last | ||
| if [ -f "./replicated/config.yaml" ]; then | ||
| echo "Merging root config.yaml last..." | ||
| yq eval-all '. as $item ireduce ({}; . * $item)' ./release/config.yaml "./replicated/config.yaml" > ./release/config.yaml.new | ||
| mv ./release/config.yaml.new ./release/config.yaml | ||
| fi | ||
|
|
||
| # Package Helm charts | ||
| - echo "Packaging Helm charts..." | ||
| - | | ||
|
|
@@ -267,7 +272,7 @@ tasks: | |
| # Navigate to chart directory, package it, and move the resulting .tgz to release folder | ||
| (cd "$chart_dir" && helm package . && mv *.tgz ../release/) | ||
| done | ||
|
|
||
| - echo "Release files prepared in ./release/ directory" | ||
| deps: | ||
| - update-version | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Base image for all shared Dockerfiles for taskfiles | ||
chris-sanders marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Use this image as base image for app specific docker 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 \ | ||
banjoh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| yq \ | ||
| gnupg \ | ||
| sudo \ | ||
chris-sanders marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # 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 \ | ||
| && 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 \ | ||
| && echo "devuser ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/devuser | ||
chris-sanders marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
chris-sanders marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Switch to non-root user | ||
| USER devuser | ||
|
|
||
| CMD ["bash"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| version: "3" | ||
|
|
||
| # Development environment tasks | ||
| tasks: | ||
| build-image: | ||
| desc: Build development Docker image | ||
| vars: | ||
| IMAGE_NAME: '{{.IMAGE_NAME}}' | ||
| IMAGE_TAG: '{{.IMAGE_TAG | default "latest"}}' | ||
| CONTAINERFILE: '{{.CONTAINERFILE | default "./container/Containerfile"}}' | ||
| BUILD_ARGS: '{{.BUILD_ARGS | default ""}}' | ||
| requires: | ||
| vars: [IMAGE_NAME, IMAGE_TAG, CONTAINERFILE] | ||
|
|
||
| cmds: | ||
| - docker build -t {{.IMAGE_NAME}} -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: | ||
| IMAGE_NAME: '{{.IMAGE_NAME}}' | ||
| CONTAINER_NAME: '{{.CONTAINER_NAME}}' | ||
| IMAGE_TAG: '{{.IMAGE_TAG | default "latest"}}' | ||
| requires: | ||
| vars: [IMAGE_NAME, CONTAINER_NAME, REPLICATED_API_TOKEN] | ||
|
|
||
| status: | ||
| - docker ps | grep -q "{{.CONTAINER_NAME}}" | ||
| cmds: | ||
| - | | ||
| # Start container with host networking for kubectl port-forward compatibility | ||
| CONTAINER_ID=$(docker run --rm --name {{.CONTAINER_NAME}} -d \ | ||
| -v $(pwd):/workspace \ | ||
| -e HOME=/home/devuser \ | ||
| -e USER=devuser \ | ||
| -e REPLICATED_API_TOKEN={{ .REPLICATED_API_TOKEN }} \ | ||
| -w /workspace \ | ||
| {{.IMAGE_NAME}}:{{.IMAGE_TAG}} bash -c 'trap "exit" TERM; while :; do sleep 0.1; done') | ||
chris-sanders marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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: [CONTAINER_NAME] | ||
| deps: | ||
| - start-implementation | ||
| cmds: | ||
| - echo "Connecting to {{.CONTAINER_NAME}}..." | ||
| - docker exec -it {{.CONTAINER_NAME}} /bin/bash | ||
|
|
||
| stop: | ||
| desc: Stop development container | ||
| silent: true | ||
| requires: | ||
| vars: [CONTAINER_NAME] | ||
| cmds: | ||
| - | | ||
| if docker ps | grep -q "{{.CONTAINER_NAME}}"; then | ||
| echo "Stopping {{.CONTAINER_NAME}} development container..." | ||
| docker stop {{.CONTAINER_NAME}} | ||
| else | ||
| echo "Container {{.CONTAINER_NAME}} is not running" | ||
| fi | ||
| restart: | ||
| desc: Restart development container | ||
| silent: true | ||
| requires: | ||
| vars: [CONTAINER_NAME] | ||
| cmds: | ||
| - task: stop | ||
| - task: start | ||
Uh oh!
There was an error while loading. Please reload this page.