Skip to content

Commit

Permalink
ecamp3-logging: add workflow to deploy it with github actions
Browse files Browse the repository at this point in the history
Use set -a to export the variables in .env directly.
We can only use single line env variables as vars and secrets here.
  • Loading branch information
BacLuc committed Nov 2, 2024
1 parent 847cd4e commit 46ef00a
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 27 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/deploy-ecamp3-logging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Deploy ecamp3-logging

on:
workflow_dispatch:
inputs:
environment:
description: 'Choose environment'
type: environment
required: true

jobs:
deploy-ecamp3-logging:
name: "Deploy ecamp3-logging"
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment }}
steps:
- name: Validate environment
uses: actions/github-script@v7
with:
script: |
if (!"${{ github.event.inputs.environment }}".startsWith("ecamp3-logging")) {
throw new Error("Environment must start with 'ecamp3-logging'");
}
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Dump secrets to .env
run: |
echo '${{ toJSON(secrets) }}' | jq -r 'keys[] as $k | select(.[$k] |contains("\n") | not) | "\($k)=\"\(.[$k])\""' >> .env
working-directory: .ops/ecamp3-logging

- name: Dump variables to .env
run: |
echo '${{ toJSON(vars) }}' | jq -r 'keys[] as $k | select(.[$k] |contains("\n") | not) | "\($k)=\"\(.[$k])\""' >> .env
working-directory: .ops/ecamp3-logging

- name: Show .env for debugging
run: echo "$(cat .env | sort)"
working-directory: .ops/ecamp3-logging

- name: Setup helm
run: |
mkdir ~/.kube && echo '${{ secrets.KUBECONFIG }}' > ~/.kube/config && chmod go-r ~/.kube/config
- name: Add helm repositories
run: |
helm repo add fluent https://fluent.github.io/helm-charts
helm repo update
- name: Diff deployment
run: |
./deploy.sh diff || true
working-directory: .ops/ecamp3-logging

- name: Show values.out.yaml
run: cat values.out.yaml
working-directory: .ops/ecamp3-logging

- name: Deploy
run: |
./deploy.sh deploy
working-directory: .ops/ecamp3-logging
3 changes: 2 additions & 1 deletion .ops/ecamp3-logging/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/charts
.env
/charts
/values.out.yaml
2 changes: 2 additions & 0 deletions .ops/ecamp3-logging/.helmignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.env
/deploy.sh
/values.out.yaml
4 changes: 1 addition & 3 deletions .ops/ecamp3-logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,5 @@ sh files/kibana/restore-kibana-objects.sh

To diff the deployment
```shell
helm template \
--namespace ecamp3-logging --no-hooks --skip-tests \
ecamp3-logging . --values=values.yaml --values=values-prod.yaml | kubectl diff --namespace ecamp3-logging -f - | batcat -l diff -
./deploy.sh diff
```
37 changes: 23 additions & 14 deletions .ops/ecamp3-logging/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
#!/bin/bash
#!/bin/sh

set -e
set -ea

SCRIPT_DIR=$(realpath "$(dirname "$0")")
cd $SCRIPT_DIR

if [ $# -ne 1 ]; then
echo "Usage: $0 <prod|dev>"
echo "(or other environments)"
exit 1
fi
. $SCRIPT_DIR/.env

envsubst < $SCRIPT_DIR/values.yaml > $SCRIPT_DIR/values.out.yaml || true

# to debug: --dry-run --debug
helm dep build
helm upgrade --install ecamp3-logging \
--namespace=ecamp3-logging \
--create-namespace \
$SCRIPT_DIR \
--values $SCRIPT_DIR/values.yaml \
--values $SCRIPT_DIR/values-$1.yaml

if [ $1 = "deploy" ]; then
# to debug: --dry-run --debug
helm upgrade --install ecamp3-logging \
--namespace ecamp3-logging \
--create-namespace \
$SCRIPT_DIR \
--values $SCRIPT_DIR/values.out.yaml
exit 0
fi

if [ $1 = "diff" ]; then
helm template \
--namespace ecamp3-logging --no-hooks --skip-tests ecamp3-logging \
$SCRIPT_DIR \
--values $SCRIPT_DIR/values.out.yaml | kubectl diff --namespace ecamp3-logging -f -
exit 0
fi
Empty file.
7 changes: 0 additions & 7 deletions .ops/ecamp3-logging/values-prod.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions .ops/ecamp3-logging/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ elasticsearch:
elasticNode:
resources:
requests:
memory: 1000Mi
memory: ${ELASTIC_NODE_REQUESTS_MEMORY:-1000Mi}
limits:
memory: 1000Mi
memory: ${ELASTIC_NODE_LIMITS_MEMORY:-1000Mi}
persistence:
storageClassName: do-block-storage
resources:
Expand Down

0 comments on commit 46ef00a

Please sign in to comment.