Skip to content

Commit 8d06333

Browse files
committed
verify image pull with authentication to local registry
1 parent e94c3f8 commit 8d06333

File tree

2 files changed

+67
-39
lines changed

2 files changed

+67
-39
lines changed

adr-003-docker-image-download.md

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,57 +57,33 @@ The following diagram illustrates the current stage of implementation and the en
5757

5858
```mermaid
5959
graph TD
60-
A[Current Stage: Simulated Image Fetching] --> B[Intermediate Stage: Registry Integration]
61-
B --> C[End Goal: Full Docker Image Support]
62-
63-
%% Current Stage
64-
subgraph Current
65-
A1[Simulated Fetching Logic]
66-
A2[Basic Image Listing]
67-
A3[Placeholder Pull Function]
68-
A4[Load Images from .tar Files]
69-
A5[Run Locally Loaded Images]
70-
A6[Manifest Parsing]
71-
end
72-
73-
%% Intermediate Stage
74-
subgraph Intermediate
75-
B1[Registry Interface Implementation]
76-
B2[Layer Downloading]
77-
end
78-
79-
%% End Goal
80-
subgraph EndGoal
81-
C1[Full Registry Authentication]
82-
C2[Layer Verification]
83-
C3[Layer Extraction]
84-
C4[Root Filesystem Creation]
85-
end
86-
87-
%% Connections
88-
A --> B1
89-
B1 --> B2
90-
B2 --> C1
91-
C1 --> C2
92-
C2 --> C3
93-
C3 --> C4
60+
A[Simulated Fetching Logic]:::implemented --> B[Registry Interface Implementation]:::implemented
61+
B --> C[Layer Downloading]:::inprogress
62+
C --> D[Full Registry Authentication]:::notstarted
63+
D --> E[Layer Verification]:::notstarted
64+
E --> F[Layer Extraction]:::notstarted
65+
F --> G[Root Filesystem Creation]:::notstarted
66+
67+
%% Styles
68+
classDef implemented fill:#a8d08d,stroke:#000,stroke-width:2px;
69+
classDef inprogress fill:#ffe699,stroke:#000,stroke-width:2px;
70+
classDef notstarted fill:#f4cccc,stroke:#000,stroke-width:2px;
9471
```
9572

9673
### Explanation of Stages
9774

98-
1. **Current Stage**:
75+
1. **Implemented**:
9976
- Simulated fetching logic is used to mimic image downloads.
10077
- Basic image listing functionality is implemented.
10178
- The `Pull` function exists as a placeholder without real registry interaction.
10279
- Added support for loading images from `.tar` files.
10380
- Added functionality to run locally loaded images.
104-
- Manifest parsing is now part of the current stage.
81+
- Registry interface implementation for local registries is complete.
10582

106-
2. **Intermediate Stage**:
107-
- Introduce a `Registry` interface to abstract interactions with container registries.
83+
2. **In Progress**:
10884
- Add functionality for downloading image layers from registries.
10985

110-
3. **End Goal**:
86+
3. **Not Started**:
11187
- Support full registry authentication, including private registries.
11288
- Verify the integrity of downloaded layers using checksums.
11389
- Extract layers to create a functional root filesystem for containers.

verify.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,58 @@ echo -e "\n\n==== Deleting Network ===="
5252
echo -e "\n\n==== Listing Networks After Deletion ===="
5353
./basic-docker network-list
5454

55+
# Function to clean up resources on exit
56+
cleanup() {
57+
echo "Cleaning up..."
58+
docker stop registry &>/dev/null
59+
docker rm registry &>/dev/null
60+
rm -rf auth
61+
echo "Cleanup completed."
62+
}
63+
64+
# Trap to ensure cleanup on script exit
65+
trap cleanup EXIT
66+
67+
# Step 1: Start a local Docker registry with authentication
68+
echo "Starting local Docker registry with authentication..."
69+
mkdir -p auth
70+
if ! docker run --entrypoint htpasswd httpd:2 -Bbn user password > auth/htpasswd; then
71+
echo "Error: Failed to create htpasswd file." >&2
72+
exit 1
73+
fi
74+
docker run -d -p 5000:5000 --name registry \
75+
-v $(pwd)/auth:/auth \
76+
-e "REGISTRY_AUTH=htpasswd" \
77+
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
78+
-e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \
79+
registry:2
80+
81+
# Step 2: Tag and push an image to the local registry with authentication
82+
echo "Tagging and pushing an image to the local registry with authentication..."
83+
docker tag alpine:latest localhost:5000/alpine
84+
docker login localhost:5000 -u user -p password
85+
docker push localhost:5000/alpine
86+
87+
# Step 3: Verify the image in the local registry
88+
echo "Verifying the image in the local registry..."
89+
catalog=$(curl -s -u user:password -X GET http://localhost:5000/v2/_catalog)
90+
echo "Registry catalog: $catalog"
91+
92+
# Step 4: Use basic-docker to pull and run the image from the local registry
93+
echo "Using basic-docker to pull and run the image from the local registry..."
94+
if ./basic-docker run user:password@localhost:5000/alpine /bin/sh -c "echo Hello from authenticated local registry"; then
95+
echo "basic-docker successfully pulled and ran the image."
96+
else
97+
echo "Error: basic-docker failed to pull or run the image." >&2
98+
exit 1
99+
fi
100+
101+
# Step 5: Check logs for authentication
102+
echo "Checking logs for authentication..."
103+
docker logs registry | grep "user"
104+
105+
echo "Script completed successfully."
106+
55107
# Clean up temporary directories
56108
rm -rf "$BASE_DIR"
57109

0 commit comments

Comments
 (0)