From decfbf65c93a050e9d41325d5c110bed0dcda299 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 18 Jun 2023 17:13:31 +0100 Subject: [PATCH] Move scripts to justfile --- .gitea/workflows/ci.yml | 10 ++++--- yamllint.yml => .yamllint.yml | 1 + README.md | 9 +++--- ansible/yamllint.yml | 1 - justfile | 46 +++++++++++++++++++++++++++++ scripts/ansible/deploy.sh | 7 ----- scripts/ansible/lint.sh | 13 -------- scripts/ansible/setup.sh | 13 -------- scripts/terraform/lint.sh | 7 ----- scripts/terraform/terraform.sh | 12 -------- scripts/terraform/update-secrets.sh | 7 ----- 11 files changed, 58 insertions(+), 68 deletions(-) rename yamllint.yml => .yamllint.yml (98%) delete mode 120000 ansible/yamllint.yml create mode 100644 justfile delete mode 100755 scripts/ansible/deploy.sh delete mode 100755 scripts/ansible/lint.sh delete mode 100755 scripts/ansible/setup.sh delete mode 100755 scripts/terraform/lint.sh delete mode 100755 scripts/terraform/terraform.sh delete mode 100755 scripts/terraform/update-secrets.sh diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index b191b97..7a1438a 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -8,10 +8,11 @@ jobs: - uses: actions/checkout@v3 - name: Setup Terraform uses: hashicorp/setup-terraform@v2 + - uses: extractions/setup-just@v1 - name: Init - run: ./scripts/terraform/terraform.sh init -backend=false + run: just terraform init -backend=false - name: Lint - run: ./scripts/terraform/lint.sh + run: just terraform-lint ansible: runs-on: ubuntu-latest @@ -21,12 +22,13 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.11 + - uses: extractions/setup-just@v1 # HACK: https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir - name: Fix permissions run: chmod 0755 ansible/ - name: Set up - run: ./scripts/ansible/setup.sh + run: just ansible-setup - name: Lint - run: ./scripts/ansible/lint.sh + run: just ansible-lint diff --git a/yamllint.yml b/.yamllint.yml similarity index 98% rename from yamllint.yml rename to .yamllint.yml index ff893fd..b2c9482 100644 --- a/yamllint.yml +++ b/.yamllint.yml @@ -6,6 +6,7 @@ ignore: | ansible/group_vars/all/vps-hosts.yml ansible/roles/traefik/files/traefik.yml ansible/roles/nebula/files/nebula.yml + env rules: document-start: disable diff --git a/README.md b/README.md index 434f2f5..d56f2b6 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,12 @@ - Python 3 - Locally configured SSH config (ideally deployed through [dotfiles](https://github.com/realorangeone/dotfiles)) - `ansible` installed on the system +- [`just`](https://github.com/casey/just) ## Installation -- `./scripts/ansible/setup.sh` -- `cd terraform/ && ./scripts/terraform/terraform.sh init` +- `just setup` +- `just terraform init` ### Private Settings @@ -21,5 +22,5 @@ Terraform backend secrets need to be placed in `terraform/secrets.sh`. ## Deploying -- `./scripts/ansible/deploy.sh` -- `./scripts/terraform/terraform.sh apply` +- `just ansible-deploy` +- `juts terraform apply` diff --git a/ansible/yamllint.yml b/ansible/yamllint.yml deleted file mode 120000 index ed6c4a0..0000000 --- a/ansible/yamllint.yml +++ /dev/null @@ -1 +0,0 @@ -../yamllint.yml \ No newline at end of file diff --git a/justfile b/justfile new file mode 100644 index 0000000..abf77bf --- /dev/null +++ b/justfile @@ -0,0 +1,46 @@ + +export PATH := justfile_directory() + "/env/bin:" + env_var("PATH") + +# Recipes +@default: + just --list + +ansible-setup: + python -m venv env + pip install -r ansible/dev-requirements.txt + cd ansible/ && ansible-galaxy install -r galaxy-requirements.yml --force + +# Run terraform with required environment +terraform +ARGS: + #!/usr/bin/env bash + cd terraform/ + + # Load secrets from env file (if it exists) + set -a + source ./.env || true + set +a + + terraform {{ ARGS }} + +# Download secrets +update-secrets: + cd terraform/ && bw get attachment .env --itemid c4f8b44e-ae62-442d-a9e0-02d0621c2454 + +ansible-deploy *ARGS: + cd ansible/ && ansible-playbook main.yml --vault-password-file=vault-pass.sh -K {{ ARGS }} + +terraform-lint: + just terraform validate + just terraform fmt -check -recursive + +yamllint: + yamllint -s . + +ansible-lint: yamllint + #!/usr/bin/env bash + cd ansible/ + + ansible-lint -p + ansible-playbook main.yml --syntax-check + +lint: terraform-lint ansible-lint diff --git a/scripts/ansible/deploy.sh b/scripts/ansible/deploy.sh deleted file mode 100755 index 5101172..0000000 --- a/scripts/ansible/deploy.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -cd ansible/ - -time ansible-playbook main.yml --vault-password-file=vault-pass.sh -K $@ diff --git a/scripts/ansible/lint.sh b/scripts/ansible/lint.sh deleted file mode 100755 index 8f9bc5a..0000000 --- a/scripts/ansible/lint.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -e - -PATH=${PWD}/env/bin:${PATH} - -yamllint -sc ansible/yamllint.yml ansible - -cd ansible/ - -ansible-lint -p - -ansible-playbook main.yml --syntax-check diff --git a/scripts/ansible/setup.sh b/scripts/ansible/setup.sh deleted file mode 100755 index 1badbe2..0000000 --- a/scripts/ansible/setup.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -e - -PATH=${PWD}/env/bin:${PATH} - -set -x - -python -m venv env - -pip install -r ansible/dev-requirements.txt - -cd ansible/ && ansible-galaxy install -r galaxy-requirements.yml --force diff --git a/scripts/terraform/lint.sh b/scripts/terraform/lint.sh deleted file mode 100755 index 6dabb86..0000000 --- a/scripts/terraform/lint.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -./scripts/terraform/terraform.sh validate - -./scripts/terraform/terraform.sh fmt -check -recursive diff --git a/scripts/terraform/terraform.sh b/scripts/terraform/terraform.sh deleted file mode 100755 index 35e559f..0000000 --- a/scripts/terraform/terraform.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -e - -cd terraform/ - -# Load secrets from env file (if it exists) -set -a -source ./.env || true -set +a -x - -terraform $@ diff --git a/scripts/terraform/update-secrets.sh b/scripts/terraform/update-secrets.sh deleted file mode 100755 index 8c61960..0000000 --- a/scripts/terraform/update-secrets.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -cd terraform/ - -bw get attachment .env --itemid c4f8b44e-ae62-442d-a9e0-02d0621c2454