From 799c00b392c76a6fa55be2e89f5b769ebe79b07e Mon Sep 17 00:00:00 2001 From: Bohdan Sukhomlinov Date: Sat, 20 Jul 2024 10:03:14 +0300 Subject: [PATCH 1/4] CI on release Signed-off-by: Bohdan Sukhomlinov --- .DS_Store | Bin 0 -> 6148 bytes .github/workflows/deployer.yaml | 53 ----------------------- .github/workflows/release.yaml | 73 ++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 53 deletions(-) create mode 100644 .DS_Store delete mode 100644 .github/workflows/deployer.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fb5b34fba4b0773901ace3224869cc0953779109 GIT binary patch literal 6148 zcmeHKu};G<5IsYHLOXPWF<*e_z#gg~u~$N3t4dJ|YDk2r1Y2fC_zff$Hs<~SNPGxi zz`L{C#!cE00lJgy=h*M;msiEEiO96a{T5M^h-xT|!49g5;BhXcSaUs`YB(8hfn)7pi8>-zF$*6f#6^|mZWjq8>Kz;)t=r@56?a)NB($!<#;wM z>j7F5wJz6)u zqQ)-2`y!{P>FaT(se(6GwTkEKirA=aN}%W(zfp?S$9T$oWd{${tfIEJmzlPT`I2<5 zZZ*@_*JXVgf71b+*&MaHMXl8VbwC}MIl%ivh{6~-%q_~+fl96bzyRG6X!BnR&Iuhx z4s(kbK^U6~w5i5jF^o+|f9QCT!`z}xC*v+3#;t7J4aLanm_HOcnaHBn>VP`nJFspa zn|%HsFTel$N&2J?s007X0TaZXxQ$nGXKU%@_^b_4x+omX%PmR@Dt8=9gOB1p6bX!l X+yF)nbBpLf=pO;GK`V9OM;-VE0_u|y literal 0 HcmV?d00001 diff --git a/.github/workflows/deployer.yaml b/.github/workflows/deployer.yaml deleted file mode 100644 index 2a0a72e..0000000 --- a/.github/workflows/deployer.yaml +++ /dev/null @@ -1,53 +0,0 @@ -name: Build and publish Deployer - -on: - workflow_dispatch: - push: - branches: - - main - paths: - - deployer/** - -jobs: - publish-docker-image: - name: Push Docker image to Docker Hub - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Log in to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v3 - with: - images: 2xnone/deployer - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha - type=raw,value=latest - - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: ./deployer/ - file: ./deployer/Dockerfile - push: true - platforms: linux/amd64 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..26d5b73 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,73 @@ +name: Docker Image CI + +on: + release: + types: [created] + workflow_dispatch: + inputs: + component: + description: 'Component name (e.g., releaser, mongodump)' + required: true + version: + description: 'Version number (e.g., 0.1.0)' + required: true + pull_request: + branches: [ main ] + paths: + - '**/Dockerfile' + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Extract component and semantic version + id: extract_info + run: | + if [[ "${{ github.event_name }}" == "release" ]]; then + TAG=${GITHUB_REF#refs/tags/} + COMPONENT=$(echo $TAG | cut -d'-' -f1) + SEMANTIC=$(echo $TAG | cut -d'-' -f2-) + elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + COMPONENT="${{ github.event.inputs.component }}" + SEMANTIC="${{ github.event.inputs.version }}" + elif [[ "${{ github.event_name }}" == "pull_request" ]]; then + COMPONENT=$(echo "${{ github.event.pull_request.title }}" | grep -oP '^\w+' || echo "test") + SEMANTIC="pr-${{ github.event.pull_request.number }}" + fi + echo ::set-output name=COMPONENT::$COMPONENT + echo ::set-output name=SEMANTIC::$SEMANTIC + echo "WORKFLOW_NAME=$COMPONENT Docker Image CI" >> $GITHUB_ENV + + - name: Update workflow name + run: echo "name: ${{ env.WORKFLOW_NAME }}" >> $GITHUB_WORKFLOW + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Check if Dockerfile exists + id: dockerfile_check + run: | + if [ -f "${{ steps.extract_info.outputs.COMPONENT }}/Dockerfile" ]; then + echo ::set-output name=EXISTS::true + else + echo ::set-output name=EXISTS::false + echo "No Dockerfile found for component ${{ steps.extract_info.outputs.COMPONENT }}" + exit 1 + fi + + - name: Build and push Docker image + if: steps.dockerfile_check.outputs.EXISTS == 'true' + uses: docker/build-push-action@v2 + with: + context: ./${{ steps.extract_info.outputs.COMPONENT }} + file: ./${{ steps.extract_info.outputs.COMPONENT }}/Dockerfile + push: ${{ github.event_name == 'release' }} + tags: | + ${{ secrets.DOCKER_USERNAME }}/${{ steps.extract_info.outputs.COMPONENT }}:${{ steps.extract_info.outputs.SEMANTIC }} + ${{ secrets.DOCKER_USERNAME }}/${{ steps.extract_info.outputs.COMPONENT }}:latest From b7cac7a84065f52ff22a18a7daf5864e76eb8862 Mon Sep 17 00:00:00 2001 From: Bohdan Sukhomlinov Date: Sat, 20 Jul 2024 10:04:37 +0300 Subject: [PATCH 2/4] fix str Signed-off-by: Bohdan Sukhomlinov --- .github/workflows/release.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 26d5b73..a5ae1a1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -42,7 +42,8 @@ jobs: echo "WORKFLOW_NAME=$COMPONENT Docker Image CI" >> $GITHUB_ENV - name: Update workflow name - run: echo "name: ${{ env.WORKFLOW_NAME }}" >> $GITHUB_WORKFLOW + run: | + echo "name: ${{ env.WORKFLOW_NAME }}" >> $GITHUB_WORKFLOW - name: Log in to Docker Hub uses: docker/login-action@v1 From 07a3051843d3879fbe5d7eea963586730fc25220 Mon Sep 17 00:00:00 2001 From: Bohdan Sukhomlinov Date: Sat, 20 Jul 2024 10:05:33 +0300 Subject: [PATCH 3/4] test Signed-off-by: Bohdan Sukhomlinov --- test/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test/Dockerfile diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 0000000..1131bf5 --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,2 @@ +FROM ubuntu +RUN echo "test" From bccaeb404a5b21f79dda8e2e96d40fc6484dd60d Mon Sep 17 00:00:00 2001 From: Bohdan Sukhomlinov Date: Sat, 20 Jul 2024 10:07:21 +0300 Subject: [PATCH 4/4] rename workflow Signed-off-by: Bohdan Sukhomlinov --- .github/workflows/release.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a5ae1a1..fc4940f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -37,13 +37,9 @@ jobs: COMPONENT=$(echo "${{ github.event.pull_request.title }}" | grep -oP '^\w+' || echo "test") SEMANTIC="pr-${{ github.event.pull_request.number }}" fi - echo ::set-output name=COMPONENT::$COMPONENT - echo ::set-output name=SEMANTIC::$SEMANTIC - echo "WORKFLOW_NAME=$COMPONENT Docker Image CI" >> $GITHUB_ENV - - - name: Update workflow name - run: | - echo "name: ${{ env.WORKFLOW_NAME }}" >> $GITHUB_WORKFLOW + echo "::set-output name=COMPONENT::$COMPONENT" + echo "::set-output name=SEMANTIC::$SEMANTIC" + echo "::set-output name=WORKFLOW_NAME::$COMPONENT Docker Image CI" - name: Log in to Docker Hub uses: docker/login-action@v1 @@ -55,9 +51,9 @@ jobs: id: dockerfile_check run: | if [ -f "${{ steps.extract_info.outputs.COMPONENT }}/Dockerfile" ]; then - echo ::set-output name=EXISTS::true + echo "::set-output name=EXISTS::true" else - echo ::set-output name=EXISTS::false + echo "::set-output name=EXISTS::false" echo "No Dockerfile found for component ${{ steps.extract_info.outputs.COMPONENT }}" exit 1 fi @@ -72,3 +68,7 @@ jobs: tags: | ${{ secrets.DOCKER_USERNAME }}/${{ steps.extract_info.outputs.COMPONENT }}:${{ steps.extract_info.outputs.SEMANTIC }} ${{ secrets.DOCKER_USERNAME }}/${{ steps.extract_info.outputs.COMPONENT }}:latest + + - name: Echo Workflow Name + run: | + echo "Current workflow name: ${{ steps.extract_info.outputs.WORKFLOW_NAME }}"