Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: decommission de l'environnement de preview #381

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
288 changes: 148 additions & 140 deletions .github/workflows/deploy_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,155 +4,163 @@ on:
types: [created]

jobs:
debug:
runs-on: ubuntu-latest
steps:
- uses: hmarr/debug-action@v2

deploy_preview:
if: (startsWith(github.event.comment.body, '🚀') || startsWith(github.event.comment.body, ':rocket:')) && github.event.issue.pull_request
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.id }}
cancel-in-progress: true
name: Deploy Preview ${{ github.event.issue.number }}
runs-on: ubuntu-latest
steps:
- name: Get Run URL
id: run_url
run: echo "url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" >> "$GITHUB_OUTPUT"

- name: Comment PR Preview
if: github.event.issue.state != 'closed'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
### :rocket: Prévisualisation
Deploying a new preview, follow progress in ${{ steps.run_url.outputs.url }}
comment_tag: deployment
mode: recreate
pr_number: ${{ github.event.issue.number }}

- name: React to comment
uses: dkershner6/reaction-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
commentId: ${{ github.event.comment.id }}
reaction: "+1"

- id: "get-branch"
run: echo "branch=$(gh pr view $PR_NO --repo $REPO --json headRefName --jq '.headRefName')" >> $GITHUB_OUTPUT
env:
REPO: ${{ github.repository }}
PR_NO: ${{ github.event.issue.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ steps.get-branch.outputs.branch }}

- name: Create LFS file list
run: git lfs ls-files --long | cut -d ' ' -f1 | sort > .lfs-assets-id

- name: LFS Cache
uses: actions/cache@v3
with:
path: .git/lfs/objects
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}
restore-keys: |
${{ runner.os }}-lfs-

- name: Git LFS Pull
run: git lfs pull

- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
name: github_actions
key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
known_hosts: ${{ vars.SSH_KNOWN_HOSTS }}
config: |
Host *
IdentityFile ~/.ssh/github_actions

- name: Create vault pwd file
run: echo ${{ secrets.VAULT_PWD }} > .infra/.vault_pwd.txt

- name: Install jmespath
run: |
sudo pipx inject ansible-core jmespath

- name: Run playbook
run: .bin/mna-bal deploy preview "${{ github.event.issue.number }}"
env:
ANSIBLE_VAULT_PASSWORD_FILE: .infra/.vault_pwd.txt
ANSIBLE_REMOTE_USER: deploy
ANSIBLE_BECOME_PASS: ${{ secrets.DEPLOY_PASS }}

- name: Encrypt Error log on failure
run: .bin/mna-bal deploy:log:encrypt
if: failure()
env:
ANSIBLE_VAULT_PASSWORD_FILE: .infra/.vault_pwd.txt

- name: Upload failure artifacts on failure
if: failure()
uses: actions/upload-artifact@v3
with:
name: error-logs
path: /tmp/deploy_error.log.gpg

- name: Preview Summary when failed
if: failure()
run: echo 'You can get error logs using `.bin/mna-bal deploy:log:decrypt ${{ github.run_id }}`' >> $GITHUB_STEP_SUMMARY

- name: Preview Summary
run: echo 'https://${{ github.event.issue.number }}.bal-preview.apprentissage.beta.gouv.fr/ 🚀' >> $GITHUB_STEP_SUMMARY

- name: Comment PR Preview
if: github.event.issue.state != 'closed'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
### :rocket: Prévisualisation
https://${{ github.event.issue.number }}.bal-preview.apprentissage.beta.gouv.fr/

You can access runner logs in ${{ steps.run_url.outputs.url }}

To re-deploy just add a comment with :rocket:
message: "Preview environment is decomissioned."
comment_tag: deployment
mode: recreate
pr_number: ${{ github.event.issue.number }}

- name: Comment PR Preview when failed
if: failure() && github.event.issue.state != 'closed'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
### :ambulance: Prévisualisation failed

https://${{ github.event.issue.number }}.bal-preview.apprentissage.beta.gouv.fr/

You can get error logs using `.bin/mna-bal deploy:log:decrypt ${{ github.run_id }}`
You can access runner logs in ${{ steps.run_url.outputs.url }}

To re-deploy just add a comment with :rocket:
comment_tag: deployment
mode: recreate
pr_number: ${{ github.event.issue.number }}

- name: Comment PR Preview when cancelled
if: cancelled() && github.event.issue.state != 'closed'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
### :ambulance: Prévisualisation cancelled

https://${{ github.event.issue.number }}.bal-preview.apprentissage.beta.gouv.fr/

You can access runner logs in ${{ steps.run_url.outputs.url }}

To re-deploy just add a comment with :rocket:
comment_tag: deployment
mode: recreate
pr_number: ${{ github.event.issue.number }}
# deploy_preview:
# if: (startsWith(github.event.comment.body, '🚀') || startsWith(github.event.comment.body, ':rocket:')) && github.event.issue.pull_request
# concurrency:
# group: ${{ github.workflow }}-${{ github.event.issue.id }}
# cancel-in-progress: true
# name: Deploy Preview ${{ github.event.issue.number }}
# runs-on: ubuntu-latest
# steps:
# - name: Get Run URL
# id: run_url
# run: echo "url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" >> "$GITHUB_OUTPUT"

# - name: Comment PR Preview
# if: github.event.issue.state != 'closed'
# uses: thollander/actions-comment-pull-request@v2
# with:
# message: |
# ### :rocket: Prévisualisation
# Deploying a new preview, follow progress in ${{ steps.run_url.outputs.url }}
# comment_tag: deployment
# mode: recreate
# pr_number: ${{ github.event.issue.number }}

# - name: React to comment
# uses: dkershner6/reaction-action@v1
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# commentId: ${{ github.event.comment.id }}
# reaction: "+1"

# - id: "get-branch"
# run: echo "branch=$(gh pr view $PR_NO --repo $REPO --json headRefName --jq '.headRefName')" >> $GITHUB_OUTPUT
# env:
# REPO: ${{ github.repository }}
# PR_NO: ${{ github.event.issue.number }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# - name: Checkout
# uses: actions/checkout@v4
# with:
# ref: ${{ steps.get-branch.outputs.branch }}

# - name: Create LFS file list
# run: git lfs ls-files --long | cut -d ' ' -f1 | sort > .lfs-assets-id

# - name: LFS Cache
# uses: actions/cache@v3
# with:
# path: .git/lfs/objects
# key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}
# restore-keys: |
# ${{ runner.os }}-lfs-

# - name: Git LFS Pull
# run: git lfs pull

# - name: Install SSH key
# uses: shimataro/ssh-key-action@v2
# with:
# name: github_actions
# key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
# known_hosts: ${{ vars.SSH_KNOWN_HOSTS }}
# config: |
# Host *
# IdentityFile ~/.ssh/github_actions

# - name: Create vault pwd file
# run: echo ${{ secrets.VAULT_PWD }} > .infra/.vault_pwd.txt

# - name: Install jmespath
# run: |
# sudo pipx inject ansible-core jmespath

# - name: Run playbook
# run: .bin/mna-bal deploy preview "${{ github.event.issue.number }}"
# env:
# ANSIBLE_VAULT_PASSWORD_FILE: .infra/.vault_pwd.txt
# ANSIBLE_REMOTE_USER: deploy
# ANSIBLE_BECOME_PASS: ${{ secrets.DEPLOY_PASS }}

# - name: Encrypt Error log on failure
# run: .bin/mna-bal deploy:log:encrypt
# if: failure()
# env:
# ANSIBLE_VAULT_PASSWORD_FILE: .infra/.vault_pwd.txt

# - name: Upload failure artifacts on failure
# if: failure()
# uses: actions/upload-artifact@v3
# with:
# name: error-logs
# path: /tmp/deploy_error.log.gpg

# - name: Preview Summary when failed
# if: failure()
# run: echo 'You can get error logs using `.bin/mna-bal deploy:log:decrypt ${{ github.run_id }}`' >> $GITHUB_STEP_SUMMARY

# - name: Preview Summary
# run: echo 'https://${{ github.event.issue.number }}.bal-preview.apprentissage.beta.gouv.fr/ 🚀' >> $GITHUB_STEP_SUMMARY

# - name: Comment PR Preview
# if: github.event.issue.state != 'closed'
# uses: thollander/actions-comment-pull-request@v2
# with:
# message: |
# ### :rocket: Prévisualisation
# https://${{ github.event.issue.number }}.bal-preview.apprentissage.beta.gouv.fr/

# You can access runner logs in ${{ steps.run_url.outputs.url }}

# To re-deploy just add a comment with :rocket:
# comment_tag: deployment
# mode: recreate
# pr_number: ${{ github.event.issue.number }}

# - name: Comment PR Preview when failed
# if: failure() && github.event.issue.state != 'closed'
# uses: thollander/actions-comment-pull-request@v2
# with:
# message: |
# ### :ambulance: Prévisualisation failed

# https://${{ github.event.issue.number }}.bal-preview.apprentissage.beta.gouv.fr/

# You can get error logs using `.bin/mna-bal deploy:log:decrypt ${{ github.run_id }}`
# You can access runner logs in ${{ steps.run_url.outputs.url }}

# To re-deploy just add a comment with :rocket:
# comment_tag: deployment
# mode: recreate
# pr_number: ${{ github.event.issue.number }}

# - name: Comment PR Preview when cancelled
# if: cancelled() && github.event.issue.state != 'closed'
# uses: thollander/actions-comment-pull-request@v2
# with:
# message: |
# ### :ambulance: Prévisualisation cancelled

# https://${{ github.event.issue.number }}.bal-preview.apprentissage.beta.gouv.fr/

# You can access runner logs in ${{ steps.run_url.outputs.url }}

# To re-deploy just add a comment with :rocket:
# comment_tag: deployment
# mode: recreate
# pr_number: ${{ github.event.issue.number }}
24 changes: 0 additions & 24 deletions .github/workflows/preview.yml

This file was deleted.

7 changes: 4 additions & 3 deletions .github/workflows/preview_cleanup.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Clean Previews
on:
schedule:
- cron: "0 0 * * *"
on: []
# on:
# schedule:
# - cron: "0 0 * * *"

concurrency:
group: ${{ github.workflow }}
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: PR CI and Preview
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, closed]

jobs:
tests:
if: github.event.pull_request.state == 'open'
uses: "./.github/workflows/ci.yml"
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
12 changes: 6 additions & 6 deletions .infra/env.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ dns_name=bal-recette.apprentissage.beta.gouv.fr
host_name=bal-recette
env_type=recette

[preview]
51.68.121.207
[preview:vars]
dns_name=bal-preview.apprentissage.beta.gouv.fr
host_name=bal-preview
env_type=preview
; [preview]
; 51.68.121.207
; [preview:vars]
; dns_name=bal-preview.apprentissage.beta.gouv.fr
; host_name=bal-preview
; env_type=preview

[local]
localhost ansible_host=127.0.0.1 ansible_connection=local
Expand Down
Loading