-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathverify.sh
More file actions
executable file
·138 lines (110 loc) · 3.86 KB
/
verify.sh
File metadata and controls
executable file
·138 lines (110 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
# Script to test Lean Docker Engine
# Use a temporary directory for testing
BASE_DIR=$(mktemp -d)
CONTAINERS_DIR="$BASE_DIR/containers"
IMAGES_DIR="$BASE_DIR/images"
# Create required directories
mkdir -p "$CONTAINERS_DIR"
mkdir -p "$IMAGES_DIR"
# Build the basic-docker binary with error handling
echo "==== Building Project ===="
if ! go build -o basic-docker .; then
echo "Error: Build failed. Please check the errors above." >&2
exit 1
fi
# Display system information
echo "==== System Information ===="
./basic-docker info
echo "==========================="
# Run a simple command
echo -e "\n\n==== Running Simple Command ===="
sudo ./basic-docker run /bin/echo "Hello from container"
# List containers
echo -e "\n\n==== Listing Containers ===="
sudo ./basic-docker ps
# List images
echo -e "\n\n==== Listing Images ===="
sudo ./basic-docker images
# Test networking functionality
# Create a network
echo -e "\n\n==== Creating Network ===="
./basic-docker network-create test-network
# List networks
echo -e "\n\n==== Listing Networks ===="
./basic-docker network-list
# Delete the network
echo -e "\n\n==== Deleting Network ===="
./basic-docker network-delete net-1
# List networks again
echo -e "\n\n==== Listing Networks After Deletion ===="
./basic-docker network-list
# Function to clean up resources on exit
cleanup() {
echo "Cleaning up..."
docker stop registry &>/dev/null
docker rm registry &>/dev/null
rm -rf auth
echo "Cleanup completed."
}
# Trap to ensure cleanup on script exit
trap cleanup EXIT
# Step 1: Start a local Docker registry with authentication
echo "Starting local Docker registry with authentication..."
mkdir -p auth
if ! docker run --entrypoint htpasswd httpd:2 -Bbn user password > auth/htpasswd; then
echo "Error: Failed to create htpasswd file." >&2
exit 1
fi
docker run -d -p 5000:5000 --name registry \
-v $(pwd)/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \
registry:2
# Step 2: Ensure the alpine:latest image is pulled before tagging and pushing
if ! docker pull alpine:latest; then
echo "Error: Failed to pull alpine:latest image." >&2
exit 1
fi
# Use echo with --password-stdin for secure login
echo "password" | docker login localhost:5000 -u user --password-stdin
# Tag and push the image to the local registry
docker tag alpine:latest localhost:5000/alpine
if ! docker push localhost:5000/alpine; then
echo "Error: Failed to push the alpine:latest image to the local registry." >&2
docker logs registry >&2
exit 1
fi
# Debugging: Check if the registry is running
if ! docker ps | grep -q registry; then
echo "Error: Registry container is not running." >&2
docker logs registry >&2
exit 1
fi
# Debugging: Check registry logs before pushing
echo "Checking registry logs before pushing the image..."
docker logs registry
# Debugging: Verify registry accessibility
if ! curl -s -u user:password -X GET http://localhost:5000/v2/ > /dev/null; then
echo "Error: Unable to access the registry at localhost:5000." >&2
exit 1
fi
# Step 3: Verify the image in the local registry
echo "Verifying the image in the local registry..."
catalog=$(curl -s -u user:password -X GET http://localhost:5000/v2/_catalog)
echo "Registry catalog: $catalog"
# Step 4: Use basic-docker to run the image
if ./basic-docker run user:password@localhost:5000/alpine /bin/sh -c "echo Hello from authenticated local registry"; then
echo "basic-docker successfully pulled and ran the image."
else
echo "Error: basic-docker failed to run the image." >&2
exit 1
fi
# Step 5: Check logs for authentication
echo "Checking logs for authentication..."
docker logs registry | grep "user"
echo "Script completed successfully."
# Clean up temporary directories
rm -rf "$BASE_DIR"
echo -e "\n\n==== All tests completed ===="