1+ name : Build Docker Image
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ image_path :
7+ description : ' Full image path (e.g., docker.io/test/xxx:0.1.0)'
8+ required : true
9+ platform :
10+ description : ' Platform for the Docker image (e.g., linux/amd64, linux/arm64)'
11+ required : true
12+ build_context :
13+ description : ' Directory path for Docker build context'
14+ required : true
15+
16+ jobs :
17+ build-and-push :
18+ runs-on : ubuntu-latest
19+ permissions :
20+ contents : read
21+ packages : write
22+ steps :
23+ - name : Checkout repository
24+ uses : actions/checkout@v2
25+
26+ - name : Login to GitHub Container Registry
27+ uses : docker/login-action@v2
28+ with :
29+ registry : ghcr.io
30+ username : ${{ github.actor }}
31+ password : ${{ secrets.GITHUB_TOKEN }}
32+
33+ - name : Login to docker.io
34+ uses : docker/login-action@v2
35+ with :
36+ registry : docker.io
37+ username : ${{ secrets.DOCKER_ACCOUNT }}
38+ password : ${{ secrets.DOCKER_PWD }}
39+
40+ - name : Build Docker Image
41+ run : |
42+ BUILD_CONTEXT="${{ github.event.inputs.build_context }}"
43+ ORIGINAL_IMAGE="${{ github.event.inputs.image_path }}"
44+ PLATFORM="${{ github.event.inputs.platform }}"
45+
46+ # Build the Docker image
47+ docker build --platform $PLATFORM -t $ORIGINAL_IMAGE $BUILD_CONTEXT
48+ echo "Docker image built with context $BUILD_CONTEXT and tagged as $ORIGINAL_IMAGE"
49+
50+ - name : Push Docker Image to GHCR
51+ run : |
52+ ORIGINAL_IMAGE="${{ github.event.inputs.image_path }}"
53+ IMAGE_NAME=$(basename $ORIGINAL_IMAGE)
54+
55+ # Retag for GHCR
56+ NEW_IMAGE="ghcr.io/${{ github.repository_owner }}/${IMAGE_NAME}"
57+ docker tag $ORIGINAL_IMAGE $NEW_IMAGE
58+ echo "Image retagged from $ORIGINAL_IMAGE to $NEW_IMAGE"
59+
60+ # Push to GHCR
61+ docker push $NEW_IMAGE
62+
63+ - name : Push Docker Image to DOCKER
64+ run : |
65+ ORIGINAL_IMAGE="${{ github.event.inputs.image_path }}"
66+
67+ # Push to Docker.io
68+ docker push $ORIGINAL_IMAGE
69+ echo "Docker image pushed to $ORIGINAL_IMAGE"
0 commit comments