From 8ac4d29201884177b423db15f07452c2788b989a Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 12:22:41 +0300 Subject: [PATCH 01/25] Adds action.yml --- action.yml | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 action.yml diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..50860e2 --- /dev/null +++ b/action.yml @@ -0,0 +1,75 @@ +name: "Build, Scan and Push Image" +description: "Build, Scan and Push Image to Self Hosted Registry" +inputs: + image: + description: "Image Name" + required: true + build-args: + description: "Build Arguments" + required: false + file: + description: "Dockerfile Path" + required: false + registry: + description: "Registry URL" + required: true + default: reg.dev.krd + timeout: + description: "Timeout" + required: false + default: "10" + +outputs: + tag: + description: "Image Tag" + value: ${{ fromJson(steps.meta.outputs.json).tags[0] }} + tags: + description: "Image Tags" + value: ${{ steps.meta.outputs.tags }} + +runs: + using: "composite" + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: echo + run: echo + shell: bash + + - id: meta + name: Extract Metadata + uses: docker/metadata-action@v5 + with: + images: ${{ inputs.registry }}/${{ inputs.image }} + flavor: latest=false + tags: | + # Cache + type=raw,value=${{ github.ref_name }}-cache + + # Branches + type=ref,event=branch + type=ref,event=branch,suffix=-{{sha}},priority=8888 # 2 + + # Releases + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{version}},priority=9999 #1 + + - name: Login to Registry + uses: docker/login-action@v3 + with: + registry: ${{ inputs.registry }} + username: ${{ secrets.username }} + password: ${{ secrets.password }} + + - name: Build Docker images + uses: docker/build-push-action@v5 + with: + push: true + file: ${{ inputs.file }} + tags: ${{ steps.meta.outputs.tags }} + cache-to: type=inline + cache-from: type=registry,ref=${{ inputs.registry }}/${{ inputs.image }}:${{ github.ref_name }}-cache + build-args: ${{ inputs.build-args }} + secrets: ${{ secrets.build-secrets }} From 8d7c95e65ebfc68aaeb2ff07f092218ea84fc0ed Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 12:34:45 +0300 Subject: [PATCH 02/25] Adds more inputs Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 50860e2..c2e5e71 100644 --- a/action.yml +++ b/action.yml @@ -19,6 +19,16 @@ inputs: required: false default: "10" + username: + required: true + description: "Username for registry" + password: + required: true + description: "Password for registry" + build-secrets: + required: false + description: "Secrets for build" + outputs: tag: description: "Image Tag" @@ -60,8 +70,8 @@ runs: uses: docker/login-action@v3 with: registry: ${{ inputs.registry }} - username: ${{ secrets.username }} - password: ${{ secrets.password }} + username: ${{ inputs.username }} + password: ${{ inputs.password }} - name: Build Docker images uses: docker/build-push-action@v5 @@ -72,4 +82,4 @@ runs: cache-to: type=inline cache-from: type=registry,ref=${{ inputs.registry }}/${{ inputs.image }}:${{ github.ref_name }}-cache build-args: ${{ inputs.build-args }} - secrets: ${{ secrets.build-secrets }} + secrets: ${{ inputs.build-secrets }} From 84ea6053fc3de89ad37a3e15af46107d63a29479 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 13:38:50 +0300 Subject: [PATCH 03/25] Remove unnecessary echo step and add echo step to display metadata outputs Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index c2e5e71..2294859 100644 --- a/action.yml +++ b/action.yml @@ -43,10 +43,6 @@ runs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: echo - run: echo - shell: bash - - id: meta name: Extract Metadata uses: docker/metadata-action@v5 @@ -66,6 +62,10 @@ runs: type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{version}},priority=9999 #1 + - name: echo + run: echo "${{ steps.meta.outputs }}" + shell: bash + - name: Login to Registry uses: docker/login-action@v3 with: From a58523891b5e088ae93c0dad358a2f5ca25149f3 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 13:40:44 +0300 Subject: [PATCH 04/25] print meta Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 2294859..05f6540 100644 --- a/action.yml +++ b/action.yml @@ -63,7 +63,9 @@ runs: type=semver,pattern={{version}},priority=9999 #1 - name: echo - run: echo "${{ steps.meta.outputs }}" + run: | + echo "${{ steps.meta.outputs }}" > meta.json + cat meta.json shell: bash - name: Login to Registry From a4ef33dee32c1c3faaa90fc395e90f55e5d80e86 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 13:44:01 +0300 Subject: [PATCH 05/25] Update echo command to convert JSON string to object Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 05f6540..c1eea2c 100644 --- a/action.yml +++ b/action.yml @@ -64,7 +64,7 @@ runs: - name: echo run: | - echo "${{ steps.meta.outputs }}" > meta.json + echo "${{ fromJson(steps.meta.outputs.json) }}" > meta.json cat meta.json shell: bash From a24eedd1081d8003b68920cc21b8590d33dd276d Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 13:45:14 +0300 Subject: [PATCH 06/25] Update echo command to include tags in meta.json Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c1eea2c..84f1172 100644 --- a/action.yml +++ b/action.yml @@ -64,7 +64,7 @@ runs: - name: echo run: | - echo "${{ fromJson(steps.meta.outputs.json) }}" > meta.json + echo "${{ fromJson(steps.meta.outputs.json).tags }}" > meta.json cat meta.json shell: bash From cef2c97dfbcaa01e18f38052a2caa3a9b21b3b2e Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 13:47:28 +0300 Subject: [PATCH 07/25] Fix echo command in action.yml Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 84f1172..2beb686 100644 --- a/action.yml +++ b/action.yml @@ -64,7 +64,7 @@ runs: - name: echo run: | - echo "${{ fromJson(steps.meta.outputs.json).tags }}" > meta.json + echo "${{ steps.meta.outputs.json.tags }}" > meta.json cat meta.json shell: bash From 81a3b1a47034fc39428bad8fe15a2c4871f6ff94 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 13:48:21 +0300 Subject: [PATCH 08/25] Update echo command in action.yml Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 2beb686..731384c 100644 --- a/action.yml +++ b/action.yml @@ -64,7 +64,7 @@ runs: - name: echo run: | - echo "${{ steps.meta.outputs.json.tags }}" > meta.json + echo "${{ steps.meta.outputs.json }}" > meta.json cat meta.json shell: bash From fa80b6522fb04b8c680c24f32895b90416d45d7d Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 13:51:13 +0300 Subject: [PATCH 09/25] Update action.yml to extract the first tag from meta.json Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 731384c..28eade3 100644 --- a/action.yml +++ b/action.yml @@ -64,7 +64,7 @@ runs: - name: echo run: | - echo "${{ steps.meta.outputs.json }}" > meta.json + $(echo '${{ steps.meta.outputs.json }}' | jq -r '.tags[0]') > meta.json cat meta.json shell: bash From 870e86f2680998c87991fd2d0ba9fa0affc19f98 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 13:53:51 +0300 Subject: [PATCH 10/25] Update echo command in action.yml Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 28eade3..e26a800 100644 --- a/action.yml +++ b/action.yml @@ -64,7 +64,7 @@ runs: - name: echo run: | - $(echo '${{ steps.meta.outputs.json }}' | jq -r '.tags[0]') > meta.json + echo $(echo '${{ steps.meta.outputs.json }}' | jq -r '.tags[0]') cat meta.json shell: bash From a77e9ff0485ff65c2a127f4713bae8e3a3716245 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 13:55:08 +0300 Subject: [PATCH 11/25] Update action.yml to save tags to meta.json Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index e26a800..86b2930 100644 --- a/action.yml +++ b/action.yml @@ -64,7 +64,7 @@ runs: - name: echo run: | - echo $(echo '${{ steps.meta.outputs.json }}' | jq -r '.tags[0]') + echo $(echo '${{ steps.meta.outputs.json }}' | jq -r '.tags[0]') > meta.json cat meta.json shell: bash From c14b1df2c6232abfb92d847da6da252aff00bd2b Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 13:56:47 +0300 Subject: [PATCH 12/25] Add new step to echo and cat meta.json Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action.yml b/action.yml index 86b2930..ac80e27 100644 --- a/action.yml +++ b/action.yml @@ -65,6 +65,10 @@ runs: - name: echo run: | echo $(echo '${{ steps.meta.outputs.json }}' | jq -r '.tags[0]') > meta.json + shell: bash + + - name: dsad + run: | cat meta.json shell: bash From 80887ec86b2ffe7dfdcdc72df24aacfede5fb942 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 14:05:48 +0300 Subject: [PATCH 13/25] Add JSON output and extraction using jq Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/action.yml b/action.yml index ac80e27..e010edc 100644 --- a/action.yml +++ b/action.yml @@ -43,6 +43,26 @@ runs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Run a command and output JSON + id: run-command + shell: bash + run: | + echo '{"tags": ["tag1", "tag2", "tag3"]}' > output.json + + - name: Display JSON + run: cat output.json + shell: bash + + - name: Extract specific value from JSON using jq + id: extract-json + run: echo "::set-output name=tag::$(echo '${{ steps.run-command.outputs.json }}' | jq -r '.tags[0]')" + shell: bash + + - name: Display Extracted Value + run: | + echo "Extracted Tag: ${{ steps.extract-json.outputs.tag }}" + shell: bash + - id: meta name: Extract Metadata uses: docker/metadata-action@v5 From 00bb7fe36f4fe69abda4e065bdda36f34d0da395 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 14:08:35 +0300 Subject: [PATCH 14/25] Refactor JSON extraction in action.yml Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/action.yml b/action.yml index e010edc..75b8c57 100644 --- a/action.yml +++ b/action.yml @@ -47,21 +47,7 @@ runs: id: run-command shell: bash run: | - echo '{"tags": ["tag1", "tag2", "tag3"]}' > output.json - - - name: Display JSON - run: cat output.json - shell: bash - - - name: Extract specific value from JSON using jq - id: extract-json - run: echo "::set-output name=tag::$(echo '${{ steps.run-command.outputs.json }}' | jq -r '.tags[0]')" - shell: bash - - - name: Display Extracted Value - run: | - echo "Extracted Tag: ${{ steps.extract-json.outputs.tag }}" - shell: bash + echo ${{ fromJson(steps.meta.outputs.json) }} - id: meta name: Extract Metadata @@ -82,16 +68,6 @@ runs: type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{version}},priority=9999 #1 - - name: echo - run: | - echo $(echo '${{ steps.meta.outputs.json }}' | jq -r '.tags[0]') > meta.json - shell: bash - - - name: dsad - run: | - cat meta.json - shell: bash - - name: Login to Registry uses: docker/login-action@v3 with: From 2442fd77250337016822b3edd1dd99df5af40882 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 14:12:18 +0300 Subject: [PATCH 15/25] Refactor Docker Buildx and add JSON output for metadata Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 75b8c57..f8d4409 100644 --- a/action.yml +++ b/action.yml @@ -43,12 +43,6 @@ runs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Run a command and output JSON - id: run-command - shell: bash - run: | - echo ${{ fromJson(steps.meta.outputs.json) }} - - id: meta name: Extract Metadata uses: docker/metadata-action@v5 @@ -68,6 +62,12 @@ runs: type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{version}},priority=9999 #1 + - name: Run a command and output JSON + id: run-command + shell: bash + run: | + echo ${{ steps.meta.outputs.json }} | python -m json.tool + - name: Login to Registry uses: docker/login-action@v3 with: From d683d2ccb21bb4b3447903adbfd915a5dd212f88 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 14:16:09 +0300 Subject: [PATCH 16/25] Update action.yml to extract the first tag from JSON output Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f8d4409..99d4986 100644 --- a/action.yml +++ b/action.yml @@ -66,7 +66,7 @@ runs: id: run-command shell: bash run: | - echo ${{ steps.meta.outputs.json }} | python -m json.tool + echo ${{ steps.meta.outputs.json }} | jq '.tags[0]' -r - name: Login to Registry uses: docker/login-action@v3 From 45da6fe554e2ad9dd96fd5049b381f137e4d74d4 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 14:18:55 +0300 Subject: [PATCH 17/25] Fix command substitution in run step Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 99d4986..002b1a0 100644 --- a/action.yml +++ b/action.yml @@ -66,7 +66,7 @@ runs: id: run-command shell: bash run: | - echo ${{ steps.meta.outputs.json }} | jq '.tags[0]' -r + echo $(echo ${{ steps.meta.outputs.json }} | jq '.tags[0]' -r) - name: Login to Registry uses: docker/login-action@v3 From 6fd4e7497defc7c4abaca45f5e74d9218b060b7b Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 14:19:50 +0300 Subject: [PATCH 18/25] Update echo command in run-command step Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 002b1a0..4a88dae 100644 --- a/action.yml +++ b/action.yml @@ -66,7 +66,7 @@ runs: id: run-command shell: bash run: | - echo $(echo ${{ steps.meta.outputs.json }} | jq '.tags[0]' -r) + echo $(echo ${{ steps.meta.outputs.json }} | jq '.tags[0]') - name: Login to Registry uses: docker/login-action@v3 From a0a5013f4c022d587b747c1fdb3194b6a00e8feb Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 14:21:56 +0300 Subject: [PATCH 19/25] Add command to save meta.json and print its contents Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 4a88dae..1ddb20c 100644 --- a/action.yml +++ b/action.yml @@ -66,7 +66,9 @@ runs: id: run-command shell: bash run: | - echo $(echo ${{ steps.meta.outputs.json }} | jq '.tags[0]') + echo ${{ steps.meta.outputs.json }} > meta.json + cat meta.json + # echo $(cat meta.json | jq '.tags[0]') - name: Login to Registry uses: docker/login-action@v3 From 11452e3e2aecbd1bbbc63da214d91da80c0c5ed5 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 14:23:47 +0300 Subject: [PATCH 20/25] Remove commented out code Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/action.yml b/action.yml index 1ddb20c..f41b9ac 100644 --- a/action.yml +++ b/action.yml @@ -68,7 +68,6 @@ runs: run: | echo ${{ steps.meta.outputs.json }} > meta.json cat meta.json - # echo $(cat meta.json | jq '.tags[0]') - name: Login to Registry uses: docker/login-action@v3 From 49ece913762f15baa0c7d77b28ef1ee994f1aa06 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 14:36:17 +0300 Subject: [PATCH 21/25] Commented out unnecessary code and removed unused step Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/action.yml b/action.yml index f41b9ac..7ea1ea0 100644 --- a/action.yml +++ b/action.yml @@ -30,9 +30,9 @@ inputs: description: "Secrets for build" outputs: - tag: - description: "Image Tag" - value: ${{ fromJson(steps.meta.outputs.json).tags[0] }} + # tag: + # description: "Image Tag" + # value: ${{ fromJson(steps.meta.outputs.json).tags[0] }} tags: description: "Image Tags" value: ${{ steps.meta.outputs.tags }} @@ -62,13 +62,6 @@ runs: type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{version}},priority=9999 #1 - - name: Run a command and output JSON - id: run-command - shell: bash - run: | - echo ${{ steps.meta.outputs.json }} > meta.json - cat meta.json - - name: Login to Registry uses: docker/login-action@v3 with: From 95f45f8b526fc55ffd41c3bdb7444aad68258bf0 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 14:39:50 +0300 Subject: [PATCH 22/25] Update outputs in action.yml Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 7ea1ea0..287924a 100644 --- a/action.yml +++ b/action.yml @@ -30,9 +30,9 @@ inputs: description: "Secrets for build" outputs: - # tag: - # description: "Image Tag" - # value: ${{ fromJson(steps.meta.outputs.json).tags[0] }} + tag: + description: "Image Tag" + value: ${{ steps.meta.outputs.tags[0] }} tags: description: "Image Tags" value: ${{ steps.meta.outputs.tags }} From 4b683d74c55dbbecdbf5c73a582e49a11b921371 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 15:04:30 +0300 Subject: [PATCH 23/25] Refactor action.yml inputs and update description Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- action.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 287924a..892f1d9 100644 --- a/action.yml +++ b/action.yml @@ -14,10 +14,6 @@ inputs: description: "Registry URL" required: true default: reg.dev.krd - timeout: - description: "Timeout" - required: false - default: "10" username: required: true @@ -27,7 +23,7 @@ inputs: description: "Password for registry" build-secrets: required: false - description: "Secrets for build" + description: "Build Secrets" outputs: tag: From d8371882057273f34c811b20a03c077a4778c140 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 15:05:21 +0300 Subject: [PATCH 24/25] Add GitHub Action for building and pushing Docker images to a self-hosted registry Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- README.md | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 10f66f8..f6555c4 100644 --- a/README.md +++ b/README.md @@ -1 +1,107 @@ -# build-image-action \ No newline at end of file +# Build Image Workflow + +This GitHub Action automates the process of building and pushing a Docker image to a self-hosted registry. The workflow includes setting up Docker Buildx, extracting metadata, logging in to the registry, and building and pushing the Docker image. + +## Inputs + +### `image` (required) +- Description: Image Name +- Required: true + +### `build-args` (optional) +- Description: Build Arguments +- Required: false + +### `file` (optional) +- Description: Dockerfile Path +- Required: false + +### `registry` (required) +- Description: Registry URL +- Required: true +- Default: reg.dev.krd + +### `username` (required) +- Description: Username for the registry +- Required: true + +### `password` (required) +- Description: Password for the registry +- Required: true + +### `build-secrets` (optional) +- Description: Build Secrets +- Required: false + +## Outputs + +### `tag` +- Description: Image Tag +- Value: ${{ steps.meta.outputs.tags[0] }} + +### `tags` +- Description: Image Tags +- Value: ${{ steps.meta.outputs.tags }} + +## Workflow Steps + +1. **Set up Docker Buildx:** + - Uses: docker/setup-buildx-action@v3 + +2. **Extract Metadata:** + - Uses: docker/metadata-action@v5 + - Inputs: + - `images`: ${{ inputs.registry }}/${{ inputs.image }} + - `flavor`: latest=false + - `tags`: + - Cache: `type=raw,value=${{ github.ref_name }}-cache` + - Branches: `type=ref,event=branch`, `type=ref,event=branch,suffix=-{{sha}},priority=8888` + - Releases: `type=semver,pattern={{major}}`, `type=semver,pattern={{major}}.{{minor}}`, `type=semver,pattern={{version}},priority=9999` + +3. **Login to Registry:** + - Uses: docker/login-action@v3 + - Inputs: + - `registry`: ${{ inputs.registry }} + - `username`: ${{ inputs.username }} + - `password`: ${{ inputs.password }} + +4. **Build Docker images:** + - Uses: docker/build-push-action@v5 + - Inputs: + - `push`: true + - `file`: ${{ inputs.file }} + - `tags`: ${{ steps.meta.outputs.tags }} + - `cache-to`: `type=inline` + - `cache-from`: `type=registry,ref=${{ inputs.registry }}/${{ inputs.image }}:${{ github.ref_name }}-cache` + - `build-args`: ${{ inputs.build-args }} + - `secrets`: ${{ inputs.build-secrets }} + +## Example Usage + +```yaml +name: Build Image Workflow +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Build and Push Image + uses: ditkrg/build-image-workflow@v1 + with: + image: "my-docker-image" + registry: "my-registry.example.com" + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + build-args: "EXAMPLE=123" + build-secrets: "EXAMPLE=****" + file: "path/to/Dockerfile" +``` + +Feel free to customize the inputs and adjust the workflow based on your specific requirements. From 95ecdf2564f8ef3f339786843ebcdd3bd8085f7c Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 3 Mar 2024 15:44:38 +0300 Subject: [PATCH 25/25] Remove unnecessary step in build workflow Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index f6555c4..697bec8 100644 --- a/README.md +++ b/README.md @@ -89,9 +89,6 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout Repository - uses: actions/checkout@v2 - - name: Build and Push Image uses: ditkrg/build-image-workflow@v1 with: