From 4c4a3524ee1a976d50706ac8c08aefe4b29f3752 Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Tue, 1 Nov 2022 11:42:44 +0000 Subject: [PATCH 01/16] first commit --- .github/workflows/ci-pipeline.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/ci-pipeline.yml diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml new file mode 100644 index 0000000..ec055fc --- /dev/null +++ b/.github/workflows/ci-pipeline.yml @@ -0,0 +1,17 @@ +name: CI Github Actions +on: + push + pull_request: + branches: + - module_8 +jobs: + build: + name: Build and test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: echo FixTests + production: + name: Publish Image + steps: + - run: echo publishing \ No newline at end of file From 53dabc27d2f16cf47c38da5490b3d45268028924 Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Tue, 1 Nov 2022 11:44:26 +0000 Subject: [PATCH 02/16] 2nd commit --- .github/workflows/ci-pipeline.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index ec055fc..8b0d8b5 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -1,6 +1,8 @@ name: CI Github Actions on: - push + push: + branches: + -module_8 pull_request: branches: - module_8 From b4e35726f504c9295918e2bccebd8907c697c1b8 Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Tue, 1 Nov 2022 11:44:53 +0000 Subject: [PATCH 03/16] 3rd --- .github/workflows/ci-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index 8b0d8b5..a680d3b 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -2,7 +2,7 @@ name: CI Github Actions on: push: branches: - -module_8 + - module_8 pull_request: branches: - module_8 From b8a59f3bca25fa293e081b83b564caffc2c83bb1 Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Tue, 1 Nov 2022 11:46:07 +0000 Subject: [PATCH 04/16] 4 --- .github/workflows/ci-pipeline.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index a680d3b..a1a161e 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -15,5 +15,6 @@ jobs: - run: echo FixTests production: name: Publish Image + runs-on: ubuntu-latest steps: - run: echo publishing \ No newline at end of file From 794c8f9468ce2c10045b5363a2eb887b9daa3836 Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Tue, 1 Nov 2022 11:51:23 +0000 Subject: [PATCH 05/16] Step 1 --- .github/workflows/ci-pipeline.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index a1a161e..766e82f 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -14,7 +14,9 @@ jobs: - uses: actions/checkout@v2 - run: echo FixTests production: + needs: build name: Publish Image runs-on: ubuntu-latest + if: github.ref == 'refs/heads/module_8' && github.event_name == 'push' steps: - run: echo publishing \ No newline at end of file From 699f7498f975d05a3d224fb03994775d1be17500 Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Wed, 2 Nov 2022 11:02:34 +0000 Subject: [PATCH 06/16] stashing --- Dockerfile | 4 ++-- tests_e2e/test_e2e.py | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1386faf..9c217f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,12 +5,12 @@ WORKDIR /opt COPY . /opt RUN pip install poetry COPY pyproject.toml poetry.lock /opt/ -RUN poetry install +RUN poetry config virtualenvs.create false --local && poetry install COPY ./todo_app /opt/todo_app/ FROM base as production EXPOSE 80 -CMD poetry run gunicorn "todo_app.app:create_app()" -b 0.0.0.0:80 +CMD poetry run gunicorn "todo_app.app:create_app()" -b 0.0.0.0:$PORT #ENTRYPOINT ["sh", "/opt/gunicorn.sh"] FROM base as development diff --git a/tests_e2e/test_e2e.py b/tests_e2e/test_e2e.py index 4aa3e7e..2dadb71 100644 --- a/tests_e2e/test_e2e.py +++ b/tests_e2e/test_e2e.py @@ -51,11 +51,7 @@ def app_with_temp_board(): @pytest.fixture(scope='module') def driver(): - opts = webdriver.ChromeOptions() - opts.add_argument('--headless') - opts.add_argument('--no-sandbox') - opts.add_argument('--disable-dev-shm-usage') - with webdriver.Chrome(options=opts) as driver: + with webdriver.Chrome() as driver: yield driver From 421e8088d1af6c5c531de4041a699b69f7a17ce1 Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Wed, 2 Nov 2022 13:11:40 +0000 Subject: [PATCH 07/16] Dockerhub automated push 1 --- .github/workflows/ci-pipeline.yml | 32 ++++++++++++++++++++++++++++--- Dockerfile | 3 ++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index 766e82f..c045544 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -6,17 +6,43 @@ on: pull_request: branches: - module_8 + jobs: + build: name: Build and test runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: echo FixTests + - run: docker build --target test --tag todo-app:test . + - run: docker run todo-app:test tests + - run: docker run -e TRELLO_API_KEY=${{ secrets.TRELLO_API_KEY }} -e TRELLO_API_SECRET=${{ secrets.TRELLO_API_SECRET }} -e TRELLO_BOARD_ID=${{ secrets.TRELLO_BOARD_ID }} todo-app:test tests_e2e + - name: Send status to Slack workflow + id: slack + uses: act10ns/slack@v1 + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + with: + status: ${{ job.status }} + message: "GitHub Actions Result: ${{ job.status }}\n${{ github.event.pull_request.thml_url }}" + production: needs: build - name: Publish Image + name: Login to DockerHub runs-on: ubuntu-latest if: github.ref == 'refs/heads/module_8' && github.event_name == 'push' steps: - - run: echo publishing \ No newline at end of file + - uses: actions/checkout@v1 + - name: Setting up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + - name: Push Image to DockerHub + uses: docker/build-push-action@v3 + with: + context: . + file: ./Dockerfile + target: production + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/todoapp:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9c217f4..b95e046 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ COPY ./todo_app /opt/todo_app/ FROM base as production EXPOSE 80 +ENV PORT=5000 CMD poetry run gunicorn "todo_app.app:create_app()" -b 0.0.0.0:$PORT #ENTRYPOINT ["sh", "/opt/gunicorn.sh"] @@ -30,4 +31,4 @@ RUN unzip /tmp/chromedriver.zip chromedriver -d /opt/todo_app ENV PATH="${PATH}:/opt/todo_app" EXPOSE 5000 -CMD ["poetry", "run", "pytest"] +ENTRYPOINT ["poetry", "run", "pytest"] From 9e418f0d4dbaf4e778309725e6795292110f27bb Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Wed, 2 Nov 2022 13:20:43 +0000 Subject: [PATCH 08/16] Dockerhub 2 --- .github/workflows/ci-pipeline.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index c045544..3b8605d 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v2 - run: docker build --target test --tag todo-app:test . - run: docker run todo-app:test tests - - run: docker run -e TRELLO_API_KEY=${{ secrets.TRELLO_API_KEY }} -e TRELLO_API_SECRET=${{ secrets.TRELLO_API_SECRET }} -e TRELLO_BOARD_ID=${{ secrets.TRELLO_BOARD_ID }} todo-app:test tests_e2e + - run: docker run -e TRELLO_API_KEY=${{ secrets.TRELLO_API_KEY }} -e TRELLO_API_SECRET=${{ secrets.TRELLO_API_SECRET }} -e TRELLO_BOARD_ID=${{ secrets.TRELLO_BOARD_ID }} todo-app:test tests_e2e - name: Send status to Slack workflow id: slack uses: act10ns/slack@v1 @@ -32,7 +32,7 @@ jobs: runs-on: ubuntu-latest if: github.ref == 'refs/heads/module_8' && github.event_name == 'push' steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Setting up Docker Buildx uses: docker/setup-buildx-action@v2 From 748aaadf0d47f03400014ff876f676f96315ffa7 Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Wed, 2 Nov 2022 13:27:18 +0000 Subject: [PATCH 09/16] Dockerhub 3 --- .github/workflows/ci-pipeline.yml | 8 ++++++-- tests_e2e/test_e2e.py | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index 3b8605d..ecee0c1 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -10,6 +10,7 @@ on: jobs: build: + name: Build and test runs-on: ubuntu-latest steps: @@ -17,6 +18,7 @@ jobs: - run: docker build --target test --tag todo-app:test . - run: docker run todo-app:test tests - run: docker run -e TRELLO_API_KEY=${{ secrets.TRELLO_API_KEY }} -e TRELLO_API_SECRET=${{ secrets.TRELLO_API_SECRET }} -e TRELLO_BOARD_ID=${{ secrets.TRELLO_BOARD_ID }} todo-app:test tests_e2e + - name: Send status to Slack workflow id: slack uses: act10ns/slack@v1 @@ -24,20 +26,22 @@ jobs: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} with: status: ${{ job.status }} - message: "GitHub Actions Result: ${{ job.status }}\n${{ github.event.pull_request.thml_url }}" + message: "GitHub Actions Result: ${{ job.status }}\n${{ github.event.pull_request.html_url }}" production: needs: build - name: Login to DockerHub + name: Push to DockerHub runs-on: ubuntu-latest if: github.ref == 'refs/heads/module_8' && github.event_name == 'push' steps: - uses: actions/checkout@v2 + - name: Setting up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Login to DockerHub run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + - name: Push Image to DockerHub uses: docker/build-push-action@v3 with: diff --git a/tests_e2e/test_e2e.py b/tests_e2e/test_e2e.py index 2dadb71..ea5c7bb 100644 --- a/tests_e2e/test_e2e.py +++ b/tests_e2e/test_e2e.py @@ -51,7 +51,11 @@ def app_with_temp_board(): @pytest.fixture(scope='module') def driver(): - with webdriver.Chrome() as driver: + opts = webdriver.ChromeOptions() + opts.add_argument('--headless') + opts.add_argument('--no-sandbox') + opts.add_argument('--disable-dev-shm-usage') + with webdriver.Chrome(options=opts) as driver: yield driver @@ -100,3 +104,4 @@ def find_task_in_section(section_name, driver): section = driver.find_element_by_xpath(f"//*[@data-test-id='{section_name}']") tasks = section.find_elements_by_xpath("//*[@data-test-class='task']") return next(task for task in tasks if task.find_element_by_xpath("//*[contains(text(), 'Test Task')]") is not None) + \ No newline at end of file From 4b36f1ec84254a3add62ee013b6c520dad512145 Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Wed, 2 Nov 2022 14:03:53 +0000 Subject: [PATCH 10/16] Heroku Pipeline 1 --- .github/workflows/ci-pipeline.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index ecee0c1..8427652 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -49,4 +49,23 @@ jobs: file: ./Dockerfile target: production push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/todoapp:latest \ No newline at end of file + tags: ${{ secrets.DOCKERHUB_USERNAME }}/todoapp:latest + + Heroku: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Rename Container and Push + run: docker tag ${{ secrets.DOCKERHUB_USERNAME }}/todoapp:latest registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/web + run: docker push registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/web + + - name: Login to Heroku Container registry + env: + HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} + run: heroku container:login + + - name: Release + env: + HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} + run: heroku container:release web -a ${{ secrets.HEROKU_APP_NAME }} From 57eb70f19771d33a77127d6300b2e61b12dcffae Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Wed, 2 Nov 2022 14:04:09 +0000 Subject: [PATCH 11/16] heroku pipeline 2 --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b95e046..e3ab512 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,7 @@ COPY ./todo_app /opt/todo_app/ FROM base as production EXPOSE 80 -ENV PORT=5000 -CMD poetry run gunicorn "todo_app.app:create_app()" -b 0.0.0.0:$PORT +CMD poetry run gunicorn "todo_app.app:create_app()" -b 0.0.0.0:${PORT:-5000} #ENTRYPOINT ["sh", "/opt/gunicorn.sh"] FROM base as development From b2e7741d1f2eb7a5d2c92fe045597dd93801fe01 Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Wed, 2 Nov 2022 14:13:11 +0000 Subject: [PATCH 12/16] heroku pipeline 3 --- .github/workflows/ci-pipeline.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index 8427652..6aae4f3 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -50,14 +50,11 @@ jobs: target: production push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/todoapp:latest - - Heroku: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Rename Container and Push + + - name: Rename Container run: docker tag ${{ secrets.DOCKERHUB_USERNAME }}/todoapp:latest registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/web + + - name: Push Container run: docker push registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/web - name: Login to Heroku Container registry From bbb54fd24deaa6b97f6a726a312431342fe6259f Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Wed, 2 Nov 2022 14:22:17 +0000 Subject: [PATCH 13/16] Heroku pipeline 4 --- .github/workflows/ci-pipeline.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index 6aae4f3..8366de4 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -51,18 +51,12 @@ jobs: push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/todoapp:latest - - name: Rename Container - run: docker tag ${{ secrets.DOCKERHUB_USERNAME }}/todoapp:latest registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/web - - - name: Push Container - run: docker push registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/web - - - name: Login to Heroku Container registry + - name: Login to Heroku Container env: HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} run: heroku container:login - - name: Release + - name: Release TO heroku env: HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} run: heroku container:release web -a ${{ secrets.HEROKU_APP_NAME }} From 74c10ab444afb7b4dc5948907047f91ba34c1b77 Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Wed, 2 Nov 2022 14:35:32 +0000 Subject: [PATCH 14/16] Module 8 Submission 1 --- .github/workflows/ci-pipeline.yml | 10 -------- README.md | 42 ++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index 8366de4..77bab76 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -50,13 +50,3 @@ jobs: target: production push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/todoapp:latest - - - name: Login to Heroku Container - env: - HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} - run: heroku container:login - - - name: Release TO heroku - env: - HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} - run: heroku container:release web -a ${{ secrets.HEROKU_APP_NAME }} diff --git a/README.md b/README.md index e82dec9..87d4866 100644 --- a/README.md +++ b/README.md @@ -81,8 +81,42 @@ ansible-playbook my-playbook.yml -i my-inventory You will be prompted for the trello api key, secret, and board ID, which you can paste in. ## Docker -You can run 'docker-compose up' to create the Dev, Prod, and Test images. -The test results will output to the terminal. +You can run 'docker-compose up' to create the Dev, Prod, and Test images. The test results will output to the terminal. -For Prod - http://localhost -For Dev - http://localhost:5000 +For Prod - http://localhost For Dev - http://localhost:5000 + +To run the commands manually you can use: docker build --target test --tag todo-app:test . docker run todo-app:test tests docker run -e TRELLO_API_KEY=${{ secrets.TRELLO_API_KEY }} -e TRELLO_API_SECRET=${{ secrets.TRELLO_API_SECRET }} -e TRELLO_BOARD_ID=${{ secrets.TRELLO_BOARD_ID }} todo-app:test tests_e2e + +## Secrets +You must define the following secrets in GitHub Secrets section: + +For the board to work: +TRELLO_API_KEY +TRELLO_API_SECRET +TRELLO_BOARD_ID + +For slack notifications: +SLACK_WEBHOOK_URL +From thew Incoming WebHooks app in the slack app directory. + +For DockerHub +DOCKERHUB_PASSWORD +DOCKERHUB_USERNAME + +## Heroku: +My app name is +https://markdossantos-module8.herokuapp.com/ + +To deploy to Heroku from DockerHub you will need to retag the Image: +docker tag registry.heroku.com//web + +Push the image to DockerHub +docker push registry.heroku.com//web + +Release the application +heroku container:release web -a + +For automation in your CI pipeline you will need to create an API key with: +heroku authorizations:create +And save the key in Github Secrets as: +HEROKU_API_KEY \ No newline at end of file From a0c5e755c5ad0308715e072e93dfcac2f2148022 Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Wed, 2 Nov 2022 14:42:07 +0000 Subject: [PATCH 15/16] Module 8 Submission 2 --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 87d4866..c4a8f0f 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,11 @@ You can run 'docker-compose up' to create the Dev, Prod, and Test images. The te For Prod - http://localhost For Dev - http://localhost:5000 -To run the commands manually you can use: docker build --target test --tag todo-app:test . docker run todo-app:test tests docker run -e TRELLO_API_KEY=${{ secrets.TRELLO_API_KEY }} -e TRELLO_API_SECRET=${{ secrets.TRELLO_API_SECRET }} -e TRELLO_BOARD_ID=${{ secrets.TRELLO_BOARD_ID }} todo-app:test tests_e2e +To run the commands manually you can use: + +docker build --target test --tag todo-app:test . + +docker run --env-file .env todo-app:test tests_e2e ## Secrets You must define the following secrets in GitHub Secrets section: From 8afaeb39045c0f5a062679a6e0de3829d16b7e7c Mon Sep 17 00:00:00 2001 From: cyberspark13 Date: Wed, 2 Nov 2022 14:45:53 +0000 Subject: [PATCH 16/16] Module 8 Submission 3 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c4a8f0f..b175cdb 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ To run the commands manually you can use: docker build --target test --tag todo-app:test . +docker run todo-app:test tests docker run --env-file .env todo-app:test tests_e2e ## Secrets