-
Notifications
You must be signed in to change notification settings - Fork 24
55 lines (44 loc) · 1.96 KB
/
create-dockerhub-repo.yml
File metadata and controls
55 lines (44 loc) · 1.96 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
name: 🐳 Create Docker Hub Repository
on:
workflow_dispatch:
jobs:
create-repo:
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout Code
uses: actions/checkout@v4
- name: 🔍 Show deployment info
run: |
echo "🔗 Repository: ${{ github.repository }}"
echo "🌿 Branch: ${{ github.ref_name }}"
echo "📝 Commit: ${{ github.sha }}"
echo "👤 Actor: ${{ github.actor }}"
- name: 🔑 Create Docker Hub Repository
run: |
# Define Docker Hub API endpoint
DOCKER_HUB_API="https://hub.docker.com/v2/repositories"
# Login to Docker Hub API
TOKEN=$(curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"username": "${{ secrets.DOCKERHUB_USERNAME }}", "password": "${{ secrets.DOCKERHUB_TOKEN }}"}' \
https://hub.docker.com/v2/users/login/ | jq -r .token)
# Check if token was retrieved successfully
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
echo "❌ Failed to login to Docker Hub API"
exit 1
fi
# Check if repository already exists
REPO_CHECK=$(curl -s -H "Authorization: JWT $TOKEN" \
"$DOCKER_HUB_API/${{ secrets.DOCKERHUB_USERNAME }}/nitp-website")
# Create repository if it doesn't exist
if [[ $REPO_CHECK == *"not found"* ]]; then
echo "🔨 Creating Docker Hub repository: ${{ secrets.DOCKERHUB_USERNAME }}/nitp-website"
curl -s -X POST \
-H "Authorization: JWT $TOKEN" \
-H "Content-Type: application/json" \
-d '{"namespace":"${{ secrets.DOCKERHUB_USERNAME }}","name":"nitp-website","description":"NIT Patna official website","is_private":false}' \
"$DOCKER_HUB_API/${{ secrets.DOCKERHUB_USERNAME }}/"
echo "✅ Repository created successfully"
else
echo "✅ Repository already exists"
fi