|
| 1 | +version: "3" |
| 2 | + |
| 3 | +# Development environment tasks |
| 4 | +tasks: |
| 5 | + build-image: |
| 6 | + desc: Build development Docker image |
| 7 | + vars: |
| 8 | + IMAGE_NAME: '{{.IMAGE_NAME}}' |
| 9 | + IMAGE_TAG: '{{.IMAGE_TAG | default "latest"}}' |
| 10 | + DOCKERFILE: '{{.DOCKERFILE | default "Dockerfile"}}' |
| 11 | + DOCKERFILE_PATH: '{{.DOCKERFILE_PATH | default "."}}' |
| 12 | + BUILD_ARGS: '{{.BUILD_ARGS | default ""}}' |
| 13 | + requires: |
| 14 | + vars: [IMAGE_NAME, IMAGE_TAG, DOCKERFILE, DOCKERFILE_PATH] |
| 15 | + |
| 16 | + cmds: |
| 17 | + - docker build -t {{.IMAGE_NAME}} -f {{.DOCKERFILE}} {{.DOCKERFILE_PATH}} |
| 18 | + |
| 19 | + start: |
| 20 | + desc: Start development container in background |
| 21 | + silent: true |
| 22 | + vars: |
| 23 | + IMAGE_NAME: '{{.IMAGE_NAME}}' |
| 24 | + CONTAINER_NAME: '{{.CONTAINER_NAME}}' |
| 25 | + IMAGE_TAG: '{{.IMAGE_TAG | default "latest"}}' |
| 26 | + requires: |
| 27 | + vars: [IMAGE_NAME, CONTAINER_NAME] |
| 28 | + |
| 29 | + cmds: |
| 30 | + - echo "Starting {{.CONTAINER_NAME}} development container..." |
| 31 | + - | |
| 32 | + # Check if container is running |
| 33 | + if docker ps | grep -q "{{.CONTAINER_NAME}}"; then |
| 34 | + echo "Container {{.CONTAINER_NAME}} is already running" |
| 35 | + # Check if container exists but is not running |
| 36 | + elif docker ps -a | grep -q "{{.CONTAINER_NAME}}"; then |
| 37 | + echo "Container {{.CONTAINER_NAME}} exists but is not running. Starting it..." |
| 38 | + docker start {{.CONTAINER_NAME}} |
| 39 | + # Create and start new container |
| 40 | + else |
| 41 | + # Try ports 5000-5004, use the first available one |
| 42 | + PORT_FOUND=false |
| 43 | + for PORT in {5000..5004}; do |
| 44 | + if ! lsof -i :$PORT > /dev/null; then |
| 45 | + PORT_ARG="-p $PORT:$PORT" |
| 46 | + echo "Using port $PORT for MLflow UI" |
| 47 | + PORT_FOUND=true |
| 48 | + break |
| 49 | + fi |
| 50 | + done |
| 51 | +
|
| 52 | + # If all standard ports are in use, use a random port |
| 53 | + if [ "$PORT_FOUND" = "false" ]; then |
| 54 | + PORT_ARG="-P" |
| 55 | + echo "All standard ports are in use. Using a random port." |
| 56 | + fi |
| 57 | +
|
| 58 | + # Start container with host networking for kubectl port-forward compatibility |
| 59 | + CONTAINER_ID=$(docker run --name {{.CONTAINER_NAME}} --network host -d \ |
| 60 | + -v $(pwd):/workspace \ |
| 61 | + -v ~/.kube:/home/devuser/.kube \ |
| 62 | + -v ~/.helm:/home/devuser/.helm \ |
| 63 | + -v ~/.replicated:/home/devuser/.replicated \ |
| 64 | + -e SHELL=/bin/bash \ |
| 65 | + -e HOME=/home/devuser \ |
| 66 | + -e USER=devuser \ |
| 67 | + -e HOST_NETWORK=true \ |
| 68 | + -w /workspace \ |
| 69 | + {{.IMAGE_NAME}}:{{.IMAGE_TAG}} sleep infinity) |
| 70 | +
|
| 71 | + if [ $? -eq 0 ]; then |
| 72 | + echo "Development container started successfully with ID: $CONTAINER_ID" |
| 73 | + echo "Ports opened within the container will be directly accessible on your host machine." |
| 74 | + else |
| 75 | + echo "Failed to start development container" |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | + fi |
| 79 | +
|
| 80 | + ensure-running: |
| 81 | + desc: Ensure the development container is running |
| 82 | + internal: true |
| 83 | + silent: true |
| 84 | + cmds: |
| 85 | + - | |
| 86 | + if ! docker ps | grep -q "{{.CONTAINER_NAME}}"; then |
| 87 | + echo "Container {{.CONTAINER_NAME}} is not running. Starting it..." |
| 88 | + task start |
| 89 | + else |
| 90 | + echo "Container {{.CONTAINER_NAME}} is already running." |
| 91 | + fi |
| 92 | + status: |
| 93 | + - docker ps | grep -q "{{.CONTAINER_NAME}}" |
| 94 | + |
| 95 | + shell: |
| 96 | + desc: Attach to development container shell |
| 97 | + deps: [ensure-running] |
| 98 | + silent: true |
| 99 | + cmds: |
| 100 | + - echo "Connecting to {{.CONTAINER_NAME}}..." |
| 101 | + - docker exec -it {{.CONTAINER_NAME}} /bin/bash |
| 102 | + |
| 103 | + stop: |
| 104 | + desc: Stop development container |
| 105 | + silent: true |
| 106 | + cmds: |
| 107 | + - | |
| 108 | + if docker ps | grep -q "{{.CONTAINER_NAME}}"; then |
| 109 | + echo "Stopping {{.CONTAINER_NAME}} development container..." |
| 110 | + docker stop {{.CONTAINER_NAME}} |
| 111 | + else |
| 112 | + echo "Container {{.CONTAINER_NAME}} is not running" |
| 113 | + fi |
| 114 | +
|
| 115 | + restart: |
| 116 | + desc: Restart development container |
| 117 | + silent: true |
| 118 | + cmds: |
| 119 | + - task: stop |
| 120 | + - task: start |
0 commit comments