Skip to content

Commit

Permalink
add github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
omeraplak committed Feb 10, 2021
1 parent 9c8ed85 commit 9b6c8f4
Show file tree
Hide file tree
Showing 19 changed files with 1,526 additions and 20,275 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
example/node_modules
75 changes: 75 additions & 0 deletions .github/workflows/develop-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Push [Develop]

on:
push:
branches:
- develop

jobs:
example-web:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- name: Workflow run cleanup action
uses: rokroskar/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Get current time
uses: 1466587594/get-current-time@v1
id: current-time
with:
format: DDMMHm
utcOffset: "+03:00"
- name: Set up kubectl
uses: matootie/[email protected]
with:
personalAccessToken: ${{ secrets.DIGITALOCEAN_TOKEN }}
clusterName: pankod-k8s
expirationTime: 1200
- name: Get nodes
run: kubectl get nodes
- name: Get current time
uses: 1466587594/get-current-time@v1
id: current-time
with:
format: DD-MM-YYYY-HH-mm
utcOffset: "+03:00"
- name: web docker build
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: docker.pkg.github.com
repository: pankod/readmin/readmin-example
tags: sha-${{ steps.current-time.outputs.formattedTime }}
- name: Deploy readmin-example-develop to k8s
run: |
echo ${{ env.domain }}
mv ./k8s/readmin-example/Chart.yaml ./k8s/readmin-example/Chart.old.yaml &&
cat ./k8s/readmin-example/Chart.old.yaml | grep -v appVersion > ./k8s/readmin-example/Chart.yaml &&
echo -e "\r\nappVersion: sha-${{ steps.current-time.outputs.formattedTime }}\r\n" >> ./k8s/readmin-example/Chart.yaml &&
cat ./k8s/readmin-example/Chart.yaml
helm upgrade readmin-example-develop ./k8s/readmin-example --install --values=./k8s/readmin-example/values.yaml \
--set ingress.enabled=true \
--set ingress.annotations."kubernetes\.io/ingress\.class"=nginx \
--set ingress.annotations."cert-manager\.io/issuer"=letsencrypt-prod \
--set ingress.hosts[0].host=${{ env.domain }} \
--set ingress.hosts[0].paths[0]="/" \
--set ingress.tls[0].secretName=${{ env.domain }} \
--set ingress.tls[0].hosts[0]=${{ env.domain }} \
env:
domain: 'readmin.develop.pankod.com'
- name: Send custom variable to Meercode Build
uses: meercodeio/[email protected]
with:
meercode-token: ${{ secrets.MEERCODE_TOKEN }}
url: 'https://readmin.develop.pankod.com'
75 changes: 75 additions & 0 deletions .github/workflows/master-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Push [Master]

on:
push:
branches:
- master

jobs:
example-web:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- name: Workflow run cleanup action
uses: rokroskar/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Get current time
uses: 1466587594/get-current-time@v1
id: current-time
with:
format: DDMMHm
utcOffset: "+03:00"
- name: Set up kubectl
uses: matootie/[email protected]
with:
personalAccessToken: ${{ secrets.DIGITALOCEAN_TOKEN }}
clusterName: pankod-k8s
expirationTime: 1200
- name: Get nodes
run: kubectl get nodes
- name: Get current time
uses: 1466587594/get-current-time@v1
id: current-time
with:
format: DD-MM-YYYY-HH-mm
utcOffset: "+03:00"
- name: web docker build
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: docker.pkg.github.com
repository: pankod/readmin/readmin-example
tags: sha-${{ steps.current-time.outputs.formattedTime }}
- name: Deploy readmin-example to k8s
run: |
echo ${{ env.domain }}
mv ./k8s/readmin-example/Chart.yaml ./k8s/readmin-example/Chart.old.yaml &&
cat ./k8s/readmin-example/Chart.old.yaml | grep -v appVersion > ./k8s/readmin-example/Chart.yaml &&
echo -e "\r\nappVersion: sha-${{ steps.current-time.outputs.formattedTime }}\r\n" >> ./k8s/readmin-example/Chart.yaml &&
cat ./k8s/readmin-example/Chart.yaml
helm upgrade readmin-example ./k8s/readmin-example --install --values=./k8s/readmin-example/values.yaml \
--set ingress.enabled=true \
--set ingress.annotations."kubernetes\.io/ingress\.class"=nginx \
--set ingress.annotations."cert-manager\.io/issuer"=letsencrypt-prod \
--set ingress.hosts[0].host=${{ env.domain }} \
--set ingress.hosts[0].paths[0]="/" \
--set ingress.tls[0].secretName=${{ env.domain }} \
--set ingress.tls[0].hosts[0]=${{ env.domain }} \
env:
domain: 'readmin.pankod.com'
- name: Send custom variable to Meercode Build
uses: meercodeio/[email protected]
with:
meercode-token: ${{ secrets.MEERCODE_TOKEN }}
url: 'https://readmin.pankod.com'
44 changes: 44 additions & 0 deletions .github/workflows/pull-request-closed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Pull Request [closed]

on:
pull_request:
types:
- closed

jobs:
api:
runs-on: ubuntu-latest

steps:
- name: Workflow run cleanup action
uses: rokroskar/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get PR Branch Name
uses: mdecoleman/[email protected]
id: pr-branch-name
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Substring PR Branch Name
id: substring-pr-branch-name
run: |
id=$(echo ${branch:0:7})
echo "::set-output name=substring::$id"
env:
branch: ${{ steps.pr-branch-name.outputs.branch }}
- name: Set up kubectl
uses: matootie/[email protected]
with:
personalAccessToken: ${{ secrets.DIGITALOCEAN_TOKEN }}
clusterName: pankod-k8s
expirationTime: 1200
- name: Get nodes
run: |
kubectl get nodes
- name: Delete helm release
run: |
echo ${{ steps.substring-pr-branch-name.outputs.substring }}
helm delete readmin-example-${{ env.branch }}
env:
branch: ${{ steps.substring-pr-branch-name.outputs.substring }}

77 changes: 77 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Pull Request [synchronize]

on:
pull_request:
types:
- synchronize
- opened
- reopened

jobs:
example-web:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]

steps:
- name: Workflow run cleanup action
uses: rokroskar/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get PR Branch Name
uses: mdecoleman/[email protected]
id: pr-branch-name
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Substring PR Branch Name
id: substring-pr-branch-name
run: |
id=$(echo ${branch:0:7})
echo "::set-output name=substring::$id"
env:
branch: ${{ steps.pr-branch-name.outputs.branch }}
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Set up kubectl
uses: matootie/[email protected]
with:
personalAccessToken: ${{ secrets.DIGITALOCEAN_TOKEN }}
clusterName: pankod-k8s
expirationTime: 1200
- name: Get nodes
run: kubectl get nodes
- name: backoffice docker build
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: docker.pkg.github.com
repository: pankod/readmin/readmin-example
tag_with_sha: true
- name: Deploy readmin-example to k8s
run: |
mv ./k8s/readmin-example/Chart.yaml ./k8s/readmin-example/Chart.old.yaml &&
cat ./k8s/readmin-example/Chart.old.yaml | grep -v appVersion > ./k8s/readmin-example/Chart.yaml &&
echo -e "\r\nappVersion: sha-${GITHUB_SHA::7}\r\n" >> ./k8s/readmin-example/Chart.yaml &&
cat ./k8s/readmin-example/Chart.yaml
helm upgrade readmin-example-${{ env.branch }} ./k8s/readmin-example --install --atomic --values=./k8s/readmin-example/values.yaml \
--set ingress.enabled=true \
--set ingress.annotations."kubernetes\.io/ingress\.class"=nginx \
--set ingress.annotations."cert-manager\.io/issuer"=letsencrypt-prod \
--set ingress.hosts[0].host=${{ env.branch }}.${{ env.domain }} \
--set ingress.hosts[0].paths[0]="/" \
--set ingress.tls[0].secretName=${{ env.branch }}.${{ env.domain }} \
--set ingress.tls[0].hosts[0]=${{ env.branch }}.${{ env.domain }} \
env:
domain: "readmin.pankod.com"
branch: ${{ steps.substring-pr-branch-name.outputs.substring }}

- name: Send custom variable to Meercode Build
uses: meercodeio/[email protected]
with:
meercode-token: ${{ secrets.MEERCODE_TOKEN }}
url: 'https://${{ steps.substring-pr-branch-name.outputs.substring }}.readmin.pankod.com'
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:12-alpine

WORKDIR /opt/app

ENV NODE_ENV production

COPY package*.json ./

RUN npm install --dev

COPY . /opt/app

RUN npm run build

#Example
WORKDIR /opt/app/example

RUN npm install --dev

CMD [ "npm", "run", "serve" ]
23 changes: 23 additions & 0 deletions example/k8s/readmin-example/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
21 changes: 21 additions & 0 deletions example/k8s/readmin-example/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: readmin-example
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 1.16.0
21 changes: 21 additions & 0 deletions example/k8s/readmin-example/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}:https://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "readmin-example.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http:https://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "readmin-example.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "readmin-example.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http:https://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "readmin-example.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http:https://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
{{- end }}
Loading

0 comments on commit 9b6c8f4

Please sign in to comment.