From bb527edb2932509b6bc2262a120e29160f746e26 Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Thu, 29 Aug 2024 19:25:36 +0200 Subject: [PATCH 01/12] Install passlib in runner --- .github/workflows/cd.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index a1c946e83..b4d281974 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,7 +1,7 @@ name: Continuous Deployment on: - push: + pull_request: branches: [ main ] jobs: @@ -53,6 +53,14 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + - name: Install passlib required for `password_hash` ansible filter + uses: actions/checkout@v4 + uses: actions/setup-python@v5 + with: + python-version: '3.9' + cache: 'pip' # caching pip dependencies + - run: pip install -r ansible/requirements.txt + - name: Run playbook uses: dawidd6/action-ansible-playbook@009b88e9b8894bd8838475d799b7dca5024e91d5 with: From 20d21ecf15c7721bc304dc00b8b56804dc98b37b Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Thu, 29 Aug 2024 19:27:39 +0200 Subject: [PATCH 02/12] lint --- .github/workflows/cd.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index b4d281974..2288525f3 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -53,13 +53,12 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Install passlib required for `password_hash` ansible filter - uses: actions/checkout@v4 - uses: actions/setup-python@v5 - with: - python-version: '3.9' - cache: 'pip' # caching pip dependencies - - run: pip install -r ansible/requirements.txt + - name: Install passlib required for `password_hash` ansible filter + uses: actions/setup-python@v5 + with: + python-version: '3.9' + cache: 'pip' # caching pip dependencies + - run: pip install -r ansible/requirements.txt - name: Run playbook uses: dawidd6/action-ansible-playbook@009b88e9b8894bd8838475d799b7dca5024e91d5 From d1ca4c71c2223626a3542b70079095c2a67f1496 Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Thu, 29 Aug 2024 19:37:35 +0200 Subject: [PATCH 03/12] fix filename --- .github/workflows/cd.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 2288525f3..553ec7843 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -58,8 +58,7 @@ jobs: with: python-version: '3.9' cache: 'pip' # caching pip dependencies - - run: pip install -r ansible/requirements.txt - + - run: pip install -r ansible/requirements.yml - name: Run playbook uses: dawidd6/action-ansible-playbook@009b88e9b8894bd8838475d799b7dca5024e91d5 with: From 46b9d08e9962e884eb9073633e6aa7cf03c09d51 Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Thu, 29 Aug 2024 19:52:20 +0200 Subject: [PATCH 04/12] Add requirement.txt file --- .github/requirements.txt | 1 + .github/workflows/cd.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .github/requirements.txt diff --git a/.github/requirements.txt b/.github/requirements.txt new file mode 100644 index 000000000..ccb9016a7 --- /dev/null +++ b/.github/requirements.txt @@ -0,0 +1 @@ +passlib>=1.74 \ No newline at end of file diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 553ec7843..b7b161fcb 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -58,7 +58,7 @@ jobs: with: python-version: '3.9' cache: 'pip' # caching pip dependencies - - run: pip install -r ansible/requirements.yml + - run: pip install -r requirements.txt - name: Run playbook uses: dawidd6/action-ansible-playbook@009b88e9b8894bd8838475d799b7dca5024e91d5 with: From d5e8753858b0ec0d049e9aadde1cd40b695937af Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Thu, 29 Aug 2024 20:00:14 +0200 Subject: [PATCH 05/12] update filepath --- .github/workflows/cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index b7b161fcb..fa10eea61 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -58,7 +58,7 @@ jobs: with: python-version: '3.9' cache: 'pip' # caching pip dependencies - - run: pip install -r requirements.txt + - run: pip install -r .github/requirements.txt - name: Run playbook uses: dawidd6/action-ansible-playbook@009b88e9b8894bd8838475d799b7dca5024e91d5 with: From 68c379c2e199dad45367b7ba8853179d0e7548af Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Thu, 29 Aug 2024 20:06:18 +0200 Subject: [PATCH 06/12] Fix typo in version number --- .github/requirements.txt | 2 +- .github/workflows/cd.yml | 64 ++++++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/.github/requirements.txt b/.github/requirements.txt index ccb9016a7..d54056acd 100644 --- a/.github/requirements.txt +++ b/.github/requirements.txt @@ -1 +1 @@ -passlib>=1.74 \ No newline at end of file +passlib>=1.7.4 \ No newline at end of file diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index fa10eea61..09c08aeb5 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -5,47 +5,47 @@ on: branches: [ main ] jobs: - docker_push: - runs-on: ubuntu-latest + # docker_push: + # runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 + # steps: + # - name: Checkout repository + # uses: actions/checkout@v3 - # GitHub Actions do not expose the commit date, so we need to - # store it in an env variable ourselves. - - name: Get commit date - id: git_commit_date - run: "echo GIT_COMMIT_DATE=$(git log -1 --format=%cd --date=iso-strict ${{ github.sha }}) >> $GITHUB_ENV" + # # GitHub Actions do not expose the commit date, so we need to + # # store it in an env variable ourselves. + # - name: Get commit date + # id: git_commit_date + # run: "echo GIT_COMMIT_DATE=$(git log -1 --format=%cd --date=iso-strict ${{ github.sha }}) >> $GITHUB_ENV" - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + # - name: Set up QEMU + # uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + # - name: Set up Docker Buildx + # uses: docker/setup-buildx-action@v2 - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + # - name: Login to DockerHub + # uses: docker/login-action@v2 + # with: + # username: ${{ secrets.DOCKERHUB_USERNAME }} + # password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push - id: docker_build - uses: docker/build-push-action@v4 - with: - context: . - push: true - tags: tactilenews/hundred-eyes:latest - build-args: | - git_commit_sha=${{ github.sha }} - git_commit_date=${{ env.GIT_COMMIT_DATE }} + # - name: Build and push + # id: docker_build + # uses: docker/build-push-action@v4 + # with: + # context: . + # push: true + # tags: tactilenews/hundred-eyes:latest + # build-args: | + # git_commit_sha=${{ github.sha }} + # git_commit_date=${{ env.GIT_COMMIT_DATE }} - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} + # - name: Image digest + # run: echo ${{ steps.docker_build.outputs.digest }} deploy: - needs: [docker_push] + # needs: [docker_push] runs-on: ubuntu-latest concurrency: staging_environment From 84e7ec22f8f01f71f2be4342629b1696db660a1f Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Mon, 2 Sep 2024 07:10:56 +0200 Subject: [PATCH 07/12] Inject passlib in ansible venv --- .github/requirements.txt | 1 - .github/workflows/cd.yml | 9 +++------ 2 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 .github/requirements.txt diff --git a/.github/requirements.txt b/.github/requirements.txt deleted file mode 100644 index d54056acd..000000000 --- a/.github/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -passlib>=1.7.4 \ No newline at end of file diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 09c08aeb5..468e2cb2f 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -53,12 +53,9 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Install passlib required for `password_hash` ansible filter - uses: actions/setup-python@v5 - with: - python-version: '3.9' - cache: 'pip' # caching pip dependencies - - run: pip install -r .github/requirements.txt + - name: Inject passlib in ansible venv + run: pipx inject ansible passlib + - name: Run playbook uses: dawidd6/action-ansible-playbook@009b88e9b8894bd8838475d799b7dca5024e91d5 with: From aaf10bdb898687f80a29b07b0c4df23c1aaf7095 Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Mon, 2 Sep 2024 07:14:23 +0200 Subject: [PATCH 08/12] Update venv name --- .github/workflows/cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 468e2cb2f..23fc96f11 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -54,7 +54,7 @@ jobs: uses: actions/checkout@v3 - name: Inject passlib in ansible venv - run: pipx inject ansible passlib + run: pipx inject ansible-core passlib - name: Run playbook uses: dawidd6/action-ansible-playbook@009b88e9b8894bd8838475d799b7dca5024e91d5 From 6f491d1856e671189e16ff87bc23d11c33539371 Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Mon, 2 Sep 2024 07:51:49 +0200 Subject: [PATCH 09/12] Only include necessary changes --- .github/workflows/cd.yml | 66 ++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 23fc96f11..fe68a9305 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,51 +1,51 @@ name: Continuous Deployment on: - pull_request: + push: branches: [ main ] jobs: - # docker_push: - # runs-on: ubuntu-latest + docker_push: + runs-on: ubuntu-latest - # steps: - # - name: Checkout repository - # uses: actions/checkout@v3 + steps: + - name: Checkout repository + uses: actions/checkout@v3 - # # GitHub Actions do not expose the commit date, so we need to - # # store it in an env variable ourselves. - # - name: Get commit date - # id: git_commit_date - # run: "echo GIT_COMMIT_DATE=$(git log -1 --format=%cd --date=iso-strict ${{ github.sha }}) >> $GITHUB_ENV" + # GitHub Actions do not expose the commit date, so we need to + # store it in an env variable ourselves. + - name: Get commit date + id: git_commit_date + run: "echo GIT_COMMIT_DATE=$(git log -1 --format=%cd --date=iso-strict ${{ github.sha }}) >> $GITHUB_ENV" - # - name: Set up QEMU - # uses: docker/setup-qemu-action@v2 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 - # - name: Set up Docker Buildx - # uses: docker/setup-buildx-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 - # - name: Login to DockerHub - # uses: docker/login-action@v2 - # with: - # username: ${{ secrets.DOCKERHUB_USERNAME }} - # password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - # - name: Build and push - # id: docker_build - # uses: docker/build-push-action@v4 - # with: - # context: . - # push: true - # tags: tactilenews/hundred-eyes:latest - # build-args: | - # git_commit_sha=${{ github.sha }} - # git_commit_date=${{ env.GIT_COMMIT_DATE }} + - name: Build and push + id: docker_build + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: tactilenews/hundred-eyes:latest + build-args: | + git_commit_sha=${{ github.sha }} + git_commit_date=${{ env.GIT_COMMIT_DATE }} - # - name: Image digest - # run: echo ${{ steps.docker_build.outputs.digest }} + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} deploy: - # needs: [docker_push] + needs: [docker_push] runs-on: ubuntu-latest concurrency: staging_environment From 6ed0d3009252c4ebe1cf7b57e7d3a1fcd14bf377 Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Mon, 2 Sep 2024 07:54:48 +0200 Subject: [PATCH 10/12] Separate schema and data migrations --- ansible/roles/installation/tasks/main.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ansible/roles/installation/tasks/main.yml b/ansible/roles/installation/tasks/main.yml index a4ced58fb..1bdca7f43 100644 --- a/ansible/roles/installation/tasks/main.yml +++ b/ansible/roles/installation/tasks/main.yml @@ -73,7 +73,12 @@ community.docker.docker_prune: images: yes -- name: Create and migrate database +- name: Run schema migrations command: - cmd: docker compose -f docker-compose.yml -f docker-compose.prod.yml exec app bin/rails db:migrate:with_data + cmd: docker compose -f docker-compose.yml -f docker-compose.prod.yml exec app bin/rails db:migrate + chdir: /home/ansible + +- name: Run data migrations + command: + cmd: docker compose -f docker-compose.yml -f docker-compose.prod.yml exec app bin/rails data:migrate chdir: /home/ansible From 559d97b175daedefb285934d73b5a384ff750aa3 Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Mon, 2 Sep 2024 07:55:23 +0200 Subject: [PATCH 11/12] Test again --- .github/workflows/cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index fe68a9305..c1eb3c9f9 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,7 +1,7 @@ name: Continuous Deployment on: - push: + pull_request: branches: [ main ] jobs: From 07a9754e275f643dc5fbe70b3128f78b02ca07d5 Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Mon, 2 Sep 2024 09:19:43 +0200 Subject: [PATCH 12/12] Remove unrelated code changes --- .github/workflows/cd.yml | 2 +- ansible/roles/installation/tasks/main.yml | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index c1eb3c9f9..fe68a9305 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,7 +1,7 @@ name: Continuous Deployment on: - pull_request: + push: branches: [ main ] jobs: diff --git a/ansible/roles/installation/tasks/main.yml b/ansible/roles/installation/tasks/main.yml index 1bdca7f43..a4ced58fb 100644 --- a/ansible/roles/installation/tasks/main.yml +++ b/ansible/roles/installation/tasks/main.yml @@ -73,12 +73,7 @@ community.docker.docker_prune: images: yes -- name: Run schema migrations +- name: Create and migrate database command: - cmd: docker compose -f docker-compose.yml -f docker-compose.prod.yml exec app bin/rails db:migrate - chdir: /home/ansible - -- name: Run data migrations - command: - cmd: docker compose -f docker-compose.yml -f docker-compose.prod.yml exec app bin/rails data:migrate + cmd: docker compose -f docker-compose.yml -f docker-compose.prod.yml exec app bin/rails db:migrate:with_data chdir: /home/ansible