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

Deploy releases/k8s-manifests 17d8208 #59

Merged
merged 4 commits into from
Jan 17, 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
34 changes: 24 additions & 10 deletions .github/workflows/k8s-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# format comment
pr_comment="$(cat <<EOF
## build comment body
echo
echo "Builing coment body content..."
comment_body="$(cat <<EOF
\`kubectl apply\` output (excluding unchanged) for $(git describe --always --tag) was:

\`\`\`
Expand All @@ -112,14 +114,26 @@ jobs:
)"


# get last PR
last_pr_number=$(hub pr list -s merged -b "${BRANCH_DEPLOY}" -h "${BRANCH_RELEASE}" -f '%I' -L 1)


# post comment
if [ -n "${last_pr_number}" ]; then
echo "Adding comment to PR #${last_pr_number}"
hub api "/repos/${GITHUB_REPOSITORY}/issues/${last_pr_number}/comments" -f body="${pr_comment}"
## get most recent merged PR
echo
echo "Looking for most recent merged PR for branch ${BRANCH_RELEASE}..."
pr_number=$(
gh pr list \
--head "${BRANCH_RELEASE}" \
--base "${BRANCH_DEPLOY}" \
--state merged \
--limit 1 \
--json number \
--jq '.[0].number'
)


## post comment
if [ -n "${pr_number}" ]; then
echo
echo "Adding comment to PR #${pr_number}..."
gh pr comment "${pr_number}" \
--body "${comment_body}"
fi

# - uses: mxschmitt/action-tmate@v3
Expand Down
57 changes: 43 additions & 14 deletions .github/workflows/k8s-prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# build PR description body
diff_size=$(stat -c%s /tmp/kube.diff)
## build PR description body
echo
echo "Builing PR title+body content..."
diff_size=$(du -k '/tmp/kube.diff' | cut -f1)
pr_head_describe="$(git describe --always --tag)"

pr_title="Deploy ${BRANCH_RELEASE} ${pr_head_describe}"
pr_body="$(cat <<EOF
Deploy ${BRANCH_RELEASE} ${pr_head_describe}

\`kubectl diff\` reports that applying ${pr_head_describe} will change:

\`\`\`diff
Expand All @@ -63,23 +64,51 @@ jobs:
)"


# generate initial commit for base if needed
## generate initial commit for base if needed
if ! git ls-remote --exit-code --heads origin "${BRANCH_DEPLOY}"; then
git fetch origin --unshallow
_first_projected_commit=$(git rev-list --max-parents=0 --first-parent HEAD)
git push origin "${_first_projected_commit}:refs/heads/${BRANCH_DEPLOY}"
echo
echo "Existing branch ${BRANCH_DEPLOY} not found, generating initial commit..."
git fetch origin --unshallow
_first_projected_commit=$(git rev-list --max-parents=0 --first-parent HEAD)
git push origin "${_first_projected_commit}:refs/heads/${BRANCH_DEPLOY}"
fi


# check for existing PR
_existing_pr_number=$(hub pr list -h "${BRANCH_RELEASE}" -f '%I')
## check for existing PR
echo
echo "Looking for existing open PR for branch ${BRANCH_RELEASE}..."
_existing_pr_number=$(
gh pr list \
--head "${BRANCH_RELEASE}" \
--base "${BRANCH_DEPLOY}" \
--state open \
--limit 1 \
--json number \
--jq '.[0].number'
)

if [ -n "${_existing_pr_number}" ]; then
echo "Updating PR #${_existing_pr_number}"
hub issue update "${_existing_pr_number}" -F <(echo "${pr_body}")
echo
echo "Found existing PR #${_existing_pr_number}, updating description..."
pr_url=$(
gh api "/repos/${GITHUB_REPOSITORY}/pulls/${_existing_pr_number}" \
--field title="${pr_title}" \
--field body="${pr_body}" \
--jq '.url'
)
echo "Updated PR: ${pr_url}"
else
echo "Opening PR"
hub pull-request -b "${BRANCH_DEPLOY}" -h "${BRANCH_RELEASE}" -F <(echo "${pr_body}") > /tmp/pr.json
echo
echo "Opening PR..."
pr_url=$(
gh pr create \
--base "${BRANCH_DEPLOY}" \
--head "${BRANCH_RELEASE}" \
--title "${pr_title}" \
--body "${pr_body}"
)
pr_number="${pr_url##*/}"
echo "Opened PR #${pr_number}"
fi

# - uses: mxschmitt/action-tmate@v3
Expand Down
4 changes: 4 additions & 0 deletions _/Namespace/balancer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: balancer
44 changes: 44 additions & 0 deletions balancer/ConfigMap/nginx-conf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: v1
data:
nginx.conf: |
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
error_log /var/log/nginx/error_log;
access_log /var/log/nginx/access_log;
server {
listen 80;
listen [::]:80;
server_name localhost;

location /access_log {
alias /var/log/nginx/access_log;
}
location /error_log {
alias /var/log/nginx/error_log;
}

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;

#}
}
}
kind: ConfigMap
metadata:
name: nginx-conf
namespace: balancer
54 changes: 54 additions & 0 deletions balancer/Deployment/frontend-static.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -c -f nginx-docker-compose.yml -o nginx-helm-chart
kompose.version: 1.31.2 (a92241f79)
creationTimestamp: null
labels:
io.kompose.service: frontend-static
name: frontend-static
namespace: balancer
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: frontend-static
strategy:
type: Recreate
template:
metadata:
annotations:
kompose.cmd: kompose convert -c -f nginx-docker-compose.yml -o nginx-helm-chart
kompose.version: 1.31.2 (a92241f79)
creationTimestamp: null
labels:
io.kompose.network/frontend-default: 'true'
io.kompose.service: frontend-static
spec:
containers:
- env:
- name: CHOKIDAR_USEPOLLING
value: 'true'
- name: VITE_API_BASE_URL
value: 'https://devnull-as-a-service.com/dev/null'
image: 'ghcr.io/codeforphilly/balancer-main/frontend-static:latest'
name: frontend-static
ports:
- containerPort: 80
protocol: TCP
resources: {}
volumeMounts:
- mountPath: /etc/nginx/nginx.conf
name: nginx-conf
readOnly: true
subPath: nginx.conf
restartPolicy: Always
volumes:
- configMap:
items:
- key: nginx.conf
path: nginx.conf
name: nginx-conf
name: nginx-conf
status: {}
20 changes: 20 additions & 0 deletions balancer/Service/frontend-static.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -c -f nginx-docker-compose.yml -o nginx-helm-chart
kompose.version: 1.31.2 (a92241f79)
creationTimestamp: null
labels:
io.kompose.service: frontend-static
name: frontend-static
namespace: balancer
spec:
ports:
- name: http
port: 80
protocol: TCP
selector:
io.kompose.service: frontend-static
status:
loadBalancer: {}
6 changes: 3 additions & 3 deletions paws-data-pipeline/Deployment/paws-dp-chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
envFrom:
- secretRef:
name: db-pass
image: 'postgres:13.2-alpine'
image: 'postgres:15.4-alpine'
imagePullPolicy: IfNotPresent
name: paws-datapipeline-db
ports:
Expand All @@ -46,7 +46,7 @@ spec:
name: api-server-pws
- secretRef:
name: db-pass
image: 'ghcr.io/codeforphilly/paws-data-pipeline/server:2.34'
image: 'ghcr.io/codeforphilly/paws-data-pipeline/server:2.5'
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand All @@ -64,7 +64,7 @@ spec:
- mountPath: /var/lib/server/data
name: paws-data-pipeline-server-data
subPath: server-data
- image: 'ghcr.io/codeforphilly/paws-data-pipeline/client:2.34'
- image: 'ghcr.io/codeforphilly/paws-data-pipeline/client:2.5'
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down
Loading