Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
89ecf03
handle all manifests in k8s
jabez007 Sep 9, 2024
655c607
Update action.yml to handle "missing" * files
jabez007 Sep 10, 2024
42ea944
Update action.yml to sanitize inputs
jabez007 Sep 12, 2024
07f76b8
Update action.yml to include more sanitation
jabez007 Sep 12, 2024
0eb7092
Update action.yml to handle restarting resources in k8s when re-runni…
jabez007 Sep 13, 2024
f95abc8
Update action.yml to only allow non-dry-run in production
jabez007 Sep 17, 2024
9271540
update morgan to skip logging ping
jabez007 Sep 20, 2024
0486a46
Update winston.js to only format and colorize logs locally
jabez007 Sep 20, 2024
fffe711
Update request-id.js to include correlation Id
jabez007 Oct 22, 2024
21d1533
Update morgan.js to include correlation Id
jabez007 Oct 22, 2024
571efaa
Update loggerMiddleware.js to add correlation Id
jabez007 Oct 22, 2024
bd5b71e
Update axios.js to send correlation Id
jabez007 Oct 22, 2024
c37d8c5
update workflows
jabez007 Jan 4, 2025
fc73905
implement Docker compose
jabez007 Jan 4, 2025
db11252
upgrade utils to packages
jabez007 Jan 4, 2025
8e9027b
create publish workflow
jabez007 Jan 4, 2025
8ee722d
update install script
jabez007 Jan 4, 2025
dd908b8
reduce resources used by kubernetes pod
jabez007 Jan 4, 2025
66c22ee
issue with test workflow
jabez007 Jan 4, 2025
52a2153
still trying to get test workflow to run
jabez007 Jan 4, 2025
fc55054
use correct image name
jabez007 Jan 5, 2025
d17c9b9
update image name for PR build
jabez007 Jan 5, 2025
6a11a27
handle graceful shutdown on more signals
jabez007 Feb 6, 2025
d36dadc
add startup probe
jabez007 Mar 21, 2025
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
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ npm-debug.log
.dockerignore
.eslint*
.gitignore
compose.y*ml
Dockerfile
README.md
README.md
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
}
}
]
}
}
94 changes: 68 additions & 26 deletions .github/shared/kubernetes/apply/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,90 @@ inputs:
runs:
using: composite
steps:

- name: Check branch
id: check_branch
run: echo "branch_name=$(echo $GITHUB_REF | sed 's|refs/heads/||')" >> $GITHUB_ENV
shell: bash

- name: Validate dry_run usage
id: if_production
run: |
if [[ "$branch_name" == "main" || "$branch_name" == "master" ]]; then
echo "dry_run=${{ inputs.dry_run }}" >> "$GITHUB_OUTPUT"
else
echo "dry_run=true" >> "$GITHUB_OUTPUT"
fi
shell: bash

####

- name: Test kubectl access
if: ${{ inputs.debug == 'true' }}
if: ${{ steps.if_production.outputs.dry_run != 'true' && inputs.debug == 'true' }}
run: kubectl get pods
shell: bash

####

- name: Apply configmap
if: ${{ hashFiles('k8s/configmap.yaml') != '' }}
run: kubectl apply -f k8s/configmap.yaml ${{ inputs.dry_run == 'true' && '--dry-run=client' || '' }}
- name: Dry run all manifests
if: ${{ steps.if_production.outputs.dry_run == 'true' }}
run: |
for file in k8s/*.yaml k8s/*.yml; do
if [ -e "$file" ]; then
kubectl apply -f "$file" ${{ steps.if_production.outputs.dry_run == 'true' && '--dry-run=client' || '' }}
fi
done
shell: bash

- name: Describe configmap
if: ${{ hashFiles('k8s/configmap.yaml') != '' && inputs.dry_run != 'true' && inputs.debug == 'true' }}
run: kubectl describe cm $(yq -r .metadata.name k8s/configmap.yaml)
- name: Apply all manifests
if: ${{ steps.if_production.outputs.dry_run != 'true' }}
run: |
for file in k8s/*.yaml k8s/*.yml; do
if [ -e "$file" ]; then
if kubectl diff -f "$file" > /dev/null; then
kind=$(yq -r .kind "$file" | tr '[:upper:]' '[:lower:]')
case "$kind" in
deployment|statefulset|daemonset)
name=$(yq -r .metadata.name "$file")
kubectl rollout restart "$kind" "$name"
;;
*)
echo "Resource type $kind does not support rollout restart."
;;
esac
else
kubectl apply -f "$file"
fi
fi
done
shell: bash

####

- name: Apply deployment
if: ${{ hashFiles('k8s/deployment.yaml') != '' }}
run: kubectl apply -f k8s/deployment.yaml ${{ inputs.dry_run == 'true' && '--dry-run=client' || '' }}
- name: Describe resources
if: ${{ steps.if_production.outputs.dry_run != 'true' && inputs.debug == 'true' }}
run: |
for file in k8s/*.yaml k8s/*.yml; do
if [ -e "$file" ]; then
kind=$(yq -r .kind "$file")
name=$(yq -r .metadata.name "$file")
kubectl describe "$kind" "$name"
fi
done
shell: bash

- name: Describe deployment
if: ${{ hashFiles('k8s/deployment.yaml') != '' && inputs.dry_run != 'true' && inputs.debug == 'true' }}
run: kubectl describe deploy $(yq -r .metadata.name k8s/deployment.yaml)
shell: bash
####

- name: Check deployment rollout status
if: ${{ hashFiles('k8s/deployment.yaml') != '' && inputs.dry_run != 'true' }}
run: kubectl rollout status deploy $(yq -r .metadata.name k8s/deployment.yaml)
if: ${{ (hashFiles('k8s/deployment.yaml') != '' || hashFiles('k8s/deployment.yml') != '') && steps.if_production.outputs.dry_run != 'true' }}
run: |
if [ -f k8s/deployment.yaml ]; then
kubectl rollout status deploy $(yq -r .metadata.name k8s/deployment.yaml)
elif [ -f k8s/deployment.yml ]; then
kubectl rollout status deploy $(yq -r .metadata.name k8s/deployment.yml)
else
echo "No deployment file found."
fi
shell: bash

####

- name: Apply service
if: ${{ hashFiles('k8s/service.yaml') != '' }}
run: kubectl apply -f k8s/service.yaml ${{ inputs.dry_run == 'true' && '--dry-run=client' || '' }}
shell: bash

- name: Describe service
if: ${{ hashFiles('k8s/service.yaml') != '' && inputs.dry_run != 'true' && inputs.debug == 'true' }}
run: kubectl describe svc $(yq -r .metadata.name k8s/service.yaml)
shell: bash
22 changes: 11 additions & 11 deletions .github/shared/kubernetes/manifests/configmap/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ runs:
IFS=',' read -ra env_files <<< "${{ inputs.env_files }}"
output=""
for env_file in "${env_files[@]}"; do
trimmed_env_file=$(echo "$env_file" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
trimmed_env_file=$(echo "$env_file" | sed 's|^[[:space:]]*||;s|[[:space:]]*$||' | sed -e 's|[&|$]|\\&|g')
if [ -f "$trimmed_env_file" ]; then
output+="--from-env-file $trimmed_env_file "
fi
done
output=$(echo "$output" | sed 's/ $//')
output=$(echo "$output" | sed 's| $||')
echo "from_files=$output" >> "$GITHUB_OUTPUT"
shell: bash

Expand Down Expand Up @@ -53,18 +53,18 @@ runs:
run: |
regex="@@(.+)@@"
while read -r line ; do
if [[ $line =~ $regex ]] ; then
echo "Found: $line"
export VARIABLE_NAME=${BASH_REMATCH[1]}
echo "Env variable name: $VARIABLE_NAME"
echo "Value of variable: $(echo $GH_SECRETS | jq -r .$VARIABLE_NAME)"
echo "Replacing @@$VARIABLE_NAME@@ with $(echo $GH_SECRETS | jq -r .$VARIABLE_NAME)"
sed -i "s|@@$VARIABLE_NAME@@|$(echo $GH_SECRETS | jq -r .$VARIABLE_NAME)|" k8s/configmap.yaml
fi
if [[ $line =~ $regex ]] ; then
echo "Found: $line"
export VARIABLE_NAME=${BASH_REMATCH[1]}
echo "Env variable name: $VARIABLE_NAME"
echo "Value of variable: $(echo $GH_SECRETS | jq -r .$VARIABLE_NAME)"
echo "Replacing @@$VARIABLE_NAME@@ with $(echo $GH_SECRETS | jq -r .$VARIABLE_NAME)"
sed -i "s|@@$VARIABLE_NAME@@|$(echo $GH_SECRETS | jq -r .$VARIABLE_NAME | sed -e 's|[&|$.*^/\]|\\&|g')|" k8s/configmap.yaml
fi
done < k8s/configmap.yaml
shell: bash

- name: Display configmap
if: ${{ hashFiles('k8s/configmap.yaml') != '' && inputs.debug == 'true' }}
run: cat k8s/configmap.yaml
shell: bash
shell: bash
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ jobs:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: jabez007/create-express-template/.github/shared/version@master

- uses: jabez007/aws-kubectl/.github/shared/docker@master
- uses: jabez007/docker-kitchen/.github/shared/docker@master
with:
image-name: ${{ github.event.repository.name }}
debug: ${{ vars.pipeline_debug }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33 changes: 26 additions & 7 deletions .github/workflows/build_and_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,43 @@ on:
- main
- master
paths:
- 'package.json'
- 'src/**'
- 'Dockerfile'
- '.dockerignore'
- "package.json"
- "src/**"
- "Dockerfile"
- ".dockerignore"

jobs:
version_and_build_and_push:
build_and_push_to_docker:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: jabez007/create-express-template/.github/shared/version@master

- uses: jabez007/docker-kitchen/.github/shared/docker@master
with:
push: true
image-name: ${{ vars.DOCKER_USERNAME }}/${{ github.event.repository.name }}
debug: ${{ vars.pipeline_debug }}
env:
DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_TOKEN }}

build_and_push_to_ghcr:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # required if push is true
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: jabez007/create-express-template/.github/shared/version@master

- uses: jabez007/aws-kubectl/.github/shared/docker@master
- uses: jabez007/docker-kitchen/.github/shared/ghcr@master
with:
push: true
debug: ${{ vars.pipeline_debug }}
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Use Shared Action to Publish

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
publish_to_npm:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Shared Publish to NPM
uses: McCann-Hub/create-typescript-template/.github/shared/npm/publish@master
with:
node_version: 22.x
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

publish_to_ghpr:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Shared Publish to GHPR
uses: McCann-Hub/create-typescript-template/.github/shared/ghpr/publish@master
with:
node_version: 22.x
env:
GHPR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 16 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,46 @@ jobs:

strategy:
matrix:
node_version: [18.x, 20.x, 22.x]
node_version:
- 18.x
- 20.x
- 22.x

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: jabez007/create-node-template/.github/shared/node/test@master
with:
node_version: ${{ matrix.node_version }}

test_docker:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: jabez007/create-express-template/.github/shared/version@master

- uses: jabez007/aws-kubectl/.github/shared/docker@master
- uses: jabez007/docker-kitchen/.github/shared/docker@master
with:
image-name: ${{ github.event.repository.name }}
tag: test
prune: false
debug: ${{ vars.pipeline_debug }}

- name: Load image
run: |
docker load --input /tmp/${{ github.event.repository.name }}.tar
docker image ls -a
docker image ls -a

- name: Run Docker container
id: container_run
run: |
CONTAINER_ID=$(docker run -d -p 80:8888 ${{ github.repository }}:test | tail -n 1)
CONTAINER_ID=$(docker run -d -p 80:8080 --env PORT=8080 ${{ github.event.repository.name }}:test | tail -n 1)
echo "CONTAINER_ID=$CONTAINER_ID" >> "$GITHUB_OUTPUT"

- name: Test Docker container
run: |
sleep 10
Expand All @@ -57,13 +61,13 @@ jobs:
echo "Ping endpoint test failed"
exit 1
fi

- name: Stop and remove Docker container
if: always()
run: |
docker stop ${{ steps.container_run.outputs.CONTAINER_ID }}
docker rm ${{ steps.container_run.outputs.CONTAINER_ID }}

- name: Post cleanup
if: always()
run: docker image prune -f
run: docker image prune -f
7 changes: 3 additions & 4 deletions bin/github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ jobs:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: jabez007/create-express-template/.github/shared/version@master

- uses: jabez007/aws-kubectl/.github/shared/docker@master
- uses: jabez007/docker-kitchen/.github/shared/docker@master
with:
image-name: ${{ github.event.repository.name }}
debug: ${{ vars.pipeline_debug }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading
Loading