From 663550c7cfb368f68df8d7b78f474fc9b556b439 Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Thu, 16 Feb 2023 13:48:03 +0200 Subject: [PATCH 01/15] use docker in ci --- .github/backups/user_app_ci.yml | 33 ------------------ .github/backups/user_app_ci_k8s.yml | 52 ++++++++++++++++++++++++++++ .github/workflows/user_app_ci.yml | 53 +++++++++-------------------- 3 files changed, 69 insertions(+), 69 deletions(-) delete mode 100644 .github/backups/user_app_ci.yml create mode 100644 .github/backups/user_app_ci_k8s.yml diff --git a/.github/backups/user_app_ci.yml b/.github/backups/user_app_ci.yml deleted file mode 100644 index c9111d5..0000000 --- a/.github/backups/user_app_ci.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: User App CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ '*' ] - -jobs: - - user_app_ci: - - runs-on: ubuntu-latest - - steps: - - - name: build - uses: actions/checkout@v2 - - run: | - docker network create my-network - docker-compose up -d --build - - - name: prepare test environment - uses: actions/setup-python@v2 - - run: | - pip install pytest - pip install requests - - - name: test - run: pytest tests/backend_tests/ - - - name: clean - run: docker-compose down \ No newline at end of file diff --git a/.github/backups/user_app_ci_k8s.yml b/.github/backups/user_app_ci_k8s.yml new file mode 100644 index 0000000..3ddfa17 --- /dev/null +++ b/.github/backups/user_app_ci_k8s.yml @@ -0,0 +1,52 @@ +# documentation can be found at: https://minikube.sigs.k8s.io/docs/tutorials/setup_minikube_in_github_actions/ +name: User App CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ '*' ] + +jobs: + + user_app_ci: + + runs-on: ubuntu-latest + + steps: + + - uses: actions/checkout@v3 + - name: Start minikube + uses: medyagh/setup-minikube@master + + - name: Deploying Services to K8s + run: | + echo "------------------ list all available pods ------------------" + kubectl get pods -A + export SHELL=/bin/bash + eval $(minikube -p minikube docker-env) + docker build -t user-app ./app + docker build -t user-service ./user_service + echo -n "verifying images:" + docker images + echo "------------------ deploying to minikube ------------------" + kubectl apply -f infrastructure/my_network-networkpolicy.yaml + kubectl apply -f infrastructure/user-app-deployment.yaml + kubectl apply -f infrastructure/user-app-service.yaml + kubectl apply -f infrastructure/user-service-deployment.yaml + kubectl apply -f infrastructure/user-service-service.yaml + echo "------------------ waiting for pod availability ------------------" + echo $pod_name + kubectl wait --for=condition=Ready pod/$(kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep user-app) -n default --timeout=60s + echo "------------------ forwarding port for user-app ------------------" + kubectl port-forward deployment/user-app 5000:5000 & + PORT_FORWARD_PID=$! + + - name: Preparing Test Environment + uses: actions/setup-python@v2 + - run: | + pip install pytest + pip install requests + + - name: Test + run: pytest tests/backend_tests/ \ No newline at end of file diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index 3ddfa17..c9111d5 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -1,4 +1,3 @@ -# documentation can be found at: https://minikube.sigs.k8s.io/docs/tutorials/setup_minikube_in_github_actions/ name: User App CI on: @@ -15,38 +14,20 @@ jobs: steps: - - uses: actions/checkout@v3 - - name: Start minikube - uses: medyagh/setup-minikube@master - - - name: Deploying Services to K8s - run: | - echo "------------------ list all available pods ------------------" - kubectl get pods -A - export SHELL=/bin/bash - eval $(minikube -p minikube docker-env) - docker build -t user-app ./app - docker build -t user-service ./user_service - echo -n "verifying images:" - docker images - echo "------------------ deploying to minikube ------------------" - kubectl apply -f infrastructure/my_network-networkpolicy.yaml - kubectl apply -f infrastructure/user-app-deployment.yaml - kubectl apply -f infrastructure/user-app-service.yaml - kubectl apply -f infrastructure/user-service-deployment.yaml - kubectl apply -f infrastructure/user-service-service.yaml - echo "------------------ waiting for pod availability ------------------" - echo $pod_name - kubectl wait --for=condition=Ready pod/$(kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep user-app) -n default --timeout=60s - echo "------------------ forwarding port for user-app ------------------" - kubectl port-forward deployment/user-app 5000:5000 & - PORT_FORWARD_PID=$! - - - name: Preparing Test Environment - uses: actions/setup-python@v2 - - run: | - pip install pytest - pip install requests - - - name: Test - run: pytest tests/backend_tests/ \ No newline at end of file + - name: build + uses: actions/checkout@v2 + - run: | + docker network create my-network + docker-compose up -d --build + + - name: prepare test environment + uses: actions/setup-python@v2 + - run: | + pip install pytest + pip install requests + + - name: test + run: pytest tests/backend_tests/ + + - name: clean + run: docker-compose down \ No newline at end of file From e54239cce4dc53db2e0a19a0b4233e53257464fe Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Thu, 16 Feb 2023 13:51:22 +0200 Subject: [PATCH 02/15] use tags --- .github/workflows/user_app_ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index c9111d5..9f32d07 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -29,5 +29,14 @@ jobs: - name: test run: pytest tests/backend_tests/ + - name: Create Tag + run: | + TAG=$(date '+%Y%m%d-%H%M%S') + git tag $TAG + + - name: Push Tag + run: | + git push origin $TAG + - name: clean run: docker-compose down \ No newline at end of file From 0feb88a8d5ebae730d4b168f9b4f8ab94f99399b Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Thu, 16 Feb 2023 14:03:43 +0200 Subject: [PATCH 03/15] echo tags --- .github/workflows/user_app_ci.yml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index 9f32d07..a6cdfde 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -18,16 +18,16 @@ jobs: uses: actions/checkout@v2 - run: | docker network create my-network - docker-compose up -d --build - - - name: prepare test environment - uses: actions/setup-python@v2 - - run: | - pip install pytest - pip install requests - - - name: test - run: pytest tests/backend_tests/ +# docker-compose up -d --build +# +# - name: prepare test environment +# uses: actions/setup-python@v2 +# - run: | +# pip install pytest +# pip install requests +# +# - name: test +# run: pytest tests/backend_tests/ - name: Create Tag run: | @@ -36,6 +36,7 @@ jobs: - name: Push Tag run: | + echo $TAG git push origin $TAG - name: clean From 4e17a348020149ba1e192e3e56117083d8025e05 Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Thu, 16 Feb 2023 14:59:35 +0200 Subject: [PATCH 04/15] generate tag --- .github/workflows/user_app_ci.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index a6cdfde..81920d0 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -29,15 +29,17 @@ jobs: # - name: test # run: pytest tests/backend_tests/ - - name: Create Tag - run: | - TAG=$(date '+%Y%m%d-%H%M%S') - git tag $TAG - - - name: Push Tag - run: | - echo $TAG - git push origin $TAG + - name: Generate tag name + run: echo "TAG_NAME=v$(git rev-list --count HEAD)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV + + - name: Create and push tag + uses: git-actions/create-tag@v1.3 + with: + tag: ${{ env.TAG_NAME }} + message: "Release ${{ env.TAG_NAME }}" + ref: "refs/tags/${{ env.TAG_NAME }}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: clean run: docker-compose down \ No newline at end of file From 59e22e7b06d80c5c50567aa109dce7a0e602a707 Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Thu, 16 Feb 2023 15:13:17 +0200 Subject: [PATCH 05/15] generate tag --- .github/workflows/user_app_ci.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index 81920d0..d3d6e58 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -33,11 +33,27 @@ jobs: run: echo "TAG_NAME=v$(git rev-list --count HEAD)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV - name: Create and push tag - uses: git-actions/create-tag@v1.3 + id: create_tag + uses: actions/create-release@v1 with: + tag_name: ${{ env.TAG_NAME }} + release_name: Release ${{ env.TAG_NAME }} + body: Release ${{ env.TAG_NAME }} + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get the tag SHA + id: tag_sha + run: echo ::set-output name=TAG_SHA::$(git rev-list -n 1 ${{ env.TAG_NAME }}) + + - name: Push tag to main branch + uses: git-actions/push-to-another-branch@v1 + with: + branch: main tag: ${{ env.TAG_NAME }} - message: "Release ${{ env.TAG_NAME }}" - ref: "refs/tags/${{ env.TAG_NAME }}" + ref: ${{ steps.tag_sha.outputs.TAG_SHA }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From c6cd7599e1a25218da4ba04733f2343f2efa02d8 Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Tue, 21 Feb 2023 16:45:13 +0200 Subject: [PATCH 06/15] test --- .github/workflows/user_app_ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index d3d6e58..111f904 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -28,6 +28,7 @@ jobs: # # - name: test # run: pytest tests/backend_tests/ +# - name: Generate tag name run: echo "TAG_NAME=v$(git rev-list --count HEAD)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV From 3e2c6b83631828e7e282cfa74154b9c40d39a92b Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Wed, 22 Feb 2023 13:04:48 +0200 Subject: [PATCH 07/15] adding tag --- .github/workflows/user_app_ci.yml | 69 +++++++------------------------ 1 file changed, 16 insertions(+), 53 deletions(-) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index 111f904..f4befe1 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -1,62 +1,25 @@ -name: User App CI +name: Create Git Tag on: - push: - branches: [ master ] pull_request: - branches: [ '*' ] + branches: [ 'master' ] jobs: - - user_app_ci: - + create-git-tag: runs-on: ubuntu-latest - steps: - - - name: build - uses: actions/checkout@v2 - - run: | - docker network create my-network -# docker-compose up -d --build -# -# - name: prepare test environment -# uses: actions/setup-python@v2 -# - run: | -# pip install pytest -# pip install requests -# -# - name: test -# run: pytest tests/backend_tests/ -# - - - name: Generate tag name - run: echo "TAG_NAME=v$(git rev-list --count HEAD)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV - - - name: Create and push tag - id: create_tag - uses: actions/create-release@v1 + - uses: actions/checkout@v3 with: - tag_name: ${{ env.TAG_NAME }} - release_name: Release ${{ env.TAG_NAME }} - body: Release ${{ env.TAG_NAME }} - draft: false - prerelease: false - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Get the tag SHA - id: tag_sha - run: echo ::set-output name=TAG_SHA::$(git rev-list -n 1 ${{ env.TAG_NAME }}) - - - name: Push tag to main branch - uses: git-actions/push-to-another-branch@v1 + ref: ${{ github.head_ref }} + fetch-depth: 0 + - name: Commit files + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git tag -a "test_tag" -m "this is a test tag" + - name: Push changes + uses: ad-m/github-push-action@master with: - branch: main - tag: ${{ env.TAG_NAME }} - ref: ${{ steps.tag_sha.outputs.TAG_SHA }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: clean - run: docker-compose down \ No newline at end of file + force: true + tags: true + branch: ${{ github.ref }} \ No newline at end of file From 3b4b2144c6209b02b90b60af08796f755631f41d Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Wed, 22 Feb 2023 13:10:06 +0200 Subject: [PATCH 08/15] adding tag --- .github/workflows/user_app_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index f4befe1..51c7122 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -22,4 +22,4 @@ jobs: with: force: true tags: true - branch: ${{ github.ref }} \ No newline at end of file + branch: ${{ github.head_ref }} \ No newline at end of file From 097f87de9b839ef8d1c7e47bc98936862478d126 Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Wed, 22 Feb 2023 13:32:52 +0200 Subject: [PATCH 09/15] adding tag --- .github/workflows/user_app_ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index 51c7122..ad9f8bd 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -8,6 +8,9 @@ jobs: create-git-tag: runs-on: ubuntu-latest steps: + - name: Get current date + id: date + run: echo "date=$(date +'%Y-%m-%d')" >> $DATE - uses: actions/checkout@v3 with: ref: ${{ github.head_ref }} @@ -16,7 +19,7 @@ jobs: run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - git tag -a "test_tag" -m "this is a test tag" + git tag -a $DATE -m "this is a test tag" - name: Push changes uses: ad-m/github-push-action@master with: From ab2e8e6c0626dfbfd8bdba6265a7a005aac3b79a Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Wed, 22 Feb 2023 13:34:52 +0200 Subject: [PATCH 10/15] adding tag --- .github/workflows/user_app_ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index ad9f8bd..29c5da5 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Get current date id: date - run: echo "date=$(date +'%Y-%m-%d')" >> $DATE + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV - uses: actions/checkout@v3 with: ref: ${{ github.head_ref }} @@ -19,7 +19,7 @@ jobs: run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - git tag -a $DATE -m "this is a test tag" + git tag -a ${{ env.date }} -m "this is a test tag" - name: Push changes uses: ad-m/github-push-action@master with: From ca09e5c4a79d6e9e7bcc481767ed919e6924f2da Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Wed, 22 Feb 2023 13:41:16 +0200 Subject: [PATCH 11/15] creating tag from datetime + commit msg --- .github/workflows/user_app_ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index 29c5da5..7488201 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Get current date id: date - run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV + run: echo "date=$(date +'+%Y_%m_%d___%H_%M_%S')" >> $GITHUB_ENV - uses: actions/checkout@v3 with: ref: ${{ github.head_ref }} @@ -19,7 +19,7 @@ jobs: run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - git tag -a ${{ env.date }} -m "this is a test tag" + git tag -a ${{ env.date }} -m ${{ github.event.head_commit.message }} - name: Push changes uses: ad-m/github-push-action@master with: From 9571b8f0ec77f76825653fb7a71d124be09bd3f8 Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Wed, 22 Feb 2023 13:50:04 +0200 Subject: [PATCH 12/15] creating tag from datetime + commit msg --- .github/workflows/user_app_ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index 7488201..27bef3b 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -16,10 +16,13 @@ jobs: ref: ${{ github.head_ref }} fetch-depth: 0 - name: Commit files + env: + COMMIT_MESSAGE: | + git log --format=%B -n 1 ${{ github.event.pull_request.head.sha }} run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - git tag -a ${{ env.date }} -m ${{ github.event.head_commit.message }} + git tag -a ${{ env.date }} -m $COMMIT_MESSAGE - name: Push changes uses: ad-m/github-push-action@master with: From 8096b5dd9621d35b2cfa20e2825cf0f1c7c8fc97 Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Wed, 22 Feb 2023 14:22:37 +0200 Subject: [PATCH 13/15] creating tag from datetime + commit msg --- .github/workflows/user_app_ci.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index 27bef3b..5edbe67 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -13,16 +13,18 @@ jobs: run: echo "date=$(date +'+%Y_%m_%d___%H_%M_%S')" >> $GITHUB_ENV - uses: actions/checkout@v3 with: - ref: ${{ github.head_ref }} + ref: | + ${{ github.head_ref }} + ${{ github.event.pull_request.head.sha }} fetch-depth: 0 + - name: Get head git commit message + id: commit-msg + run: echo "commit-msg=$(git show -s --format=%s)" >> $GITHUB_ENV - name: Commit files - env: - COMMIT_MESSAGE: | - git log --format=%B -n 1 ${{ github.event.pull_request.head.sha }} run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - git tag -a ${{ env.date }} -m $COMMIT_MESSAGE + git tag -a ${{ env.date }} -m ${{ env.commit-msg }} - name: Push changes uses: ad-m/github-push-action@master with: From 6cc867ddab01c51b5c5f6e73a7ac3872a60f03b8 Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Wed, 22 Feb 2023 14:29:03 +0200 Subject: [PATCH 14/15] creating tag from datetime + commit msg --- .github/workflows/user_app_ci.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index 5edbe67..9b658e1 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -13,13 +13,14 @@ jobs: run: echo "date=$(date +'+%Y_%m_%d___%H_%M_%S')" >> $GITHUB_ENV - uses: actions/checkout@v3 with: - ref: | - ${{ github.head_ref }} - ${{ github.event.pull_request.head.sha }} + ref: ${{ github.head_ref }} fetch-depth: 0 - - name: Get head git commit message + name: Get head git commit message id: commit-msg - run: echo "commit-msg=$(git show -s --format=%s)" >> $GITHUB_ENV + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + - run: echo "commit-msg=$(git show -s --format=%s)" >> $GITHUB_ENV - name: Commit files run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" From 1c37c23d43c5232dcb88a6c9dd7b5c5ebcedbb3b Mon Sep 17 00:00:00 2001 From: RanMarkovich Date: Wed, 22 Feb 2023 14:31:44 +0200 Subject: [PATCH 15/15] creating tag from datetime + commit msg --- .github/workflows/user_app_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/user_app_ci.yml b/.github/workflows/user_app_ci.yml index 9b658e1..e92d43d 100644 --- a/.github/workflows/user_app_ci.yml +++ b/.github/workflows/user_app_ci.yml @@ -25,7 +25,7 @@ jobs: run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - git tag -a ${{ env.date }} -m ${{ env.commit-msg }} + git tag -a ${{ env.date }} -m "${{ env.commit-msg }}" - name: Push changes uses: ad-m/github-push-action@master with: