You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# DStack Pre-Launch Script: Private Registry Support
2
+
3
+
## Overview
4
+
5
+
This directory contains a real-world example of a pre-launch script for DStack applications. The script demonstrates how to authenticate with private container registries (Docker Hub or AWS ECR) using encrypted environment variables before launching your application.
6
+
7
+
Pre-launch scripts were introduced in DStack v0.3.5 (as detailed in [#94](https://github.com/Dstack-TEE/dstack/pull/94)) and enable applications to perform preliminary setup steps before Docker Compose initialization.
8
+
9
+
## How It Works
10
+
11
+
The script (version v0.0.1) performs the following operations:
12
+
13
+
- Checks for specific encrypted environment variables
14
+
- Authenticates with Docker Hub using the Docker CLI if Docker Hub credentials are provided
15
+
- Authenticates with AWS ECR using the AWS CLI if AWS credentials are provided
16
+
- Installs AWS CLI automatically if it's not available (when using AWS ECR)
17
+
- Performs Docker cleanup by pruning unused images and volumes
18
+
- Does nothing by default if no credentials are provided
19
+
- Exits with error code 1 if authentication fails
20
+
21
+
## Configuration
22
+
23
+
### Docker Hub Authentication
24
+
25
+
To authenticate with Docker Hub, configure these encrypted environment variables:
26
+
27
+
-`DSTACK_DOCKER_USERNAME` - Your Docker Hub username
28
+
-`DSTACK_DOCKER_PASSWORD` - Your Docker Hub password or access token
29
+
30
+
### AWS ECR Authentication
31
+
32
+
To authenticate with AWS ECR, configure these encrypted environment variables:
33
+
34
+
-`DSTACK_AWS_ACCESS_KEY_ID` - Your AWS access key ID
35
+
-`DSTACK_AWS_SECRET_ACCESS_KEY` - Your AWS secret access key
36
+
-`DSTACK_AWS_REGION` - The AWS region where your ECR repository is located
37
+
-`DSTACK_AWS_ECR_REGISTRY` - Your AWS ECR registry URL
38
+
39
+
## Usage
40
+
41
+
1. Set up the required encrypted environment variables for your chosen registry
42
+
2. Reference this pre-launch script in your `app-compose.json` file in the `pre_launch_script` section
43
+
3. Deploy your application using DStack
44
+
45
+
## Security Features
46
+
47
+
- The script uses `--password-stdin` when logging in to Docker to prevent credentials from appearing in process lists
48
+
- Credentials are handled securely, never exposed in logs or error messages
49
+
- For AWS ECR, the script verifies the AWS CLI installation package with MD5 checksum
50
+
- The script checks if you're already logged in to avoid unnecessary authentication attempts
51
+
52
+
## Notes
53
+
54
+
- The pre-launch script is executed before Docker Compose initialization
55
+
- No authentication is performed if the required environment variables are not provided
56
+
- The script automatically performs Docker cleanup to free up space by removing unused images and volumes
57
+
- You can modify the script to support additional private container registries as needed
0 commit comments