diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e5d359a..36aaaa4 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -51,8 +51,33 @@ jobs: run: | docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./frontend docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - Explore-GitHub-Actions: + deploy: + name: Deploy to EKS runs-on: arc-runner-set steps: - - run: echo "🎉 This job uses runner scale set runners!" + - name: Checkout + uses: actions/checkout@v2 + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{secrets.AWS_REGION}} + - name: Intall Helm + run: | + echo "installing helm..." + curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 + chmod 700 get_helm.sh + ./get_helm.sh + - name: Configure Kubectl + run: | + echo "configuring kubectl" + aws eks update-kubeconfig --name${{secrets.K8S_CLUSTER_NAME}} --region${{secrets.AWS_REGION}} + - name: Install/Update Helm Chart + run: | + echo "installing/updating helm chart..." + helm upgrade --install todo-app ./todo --set database.host=${{secrets.DB_HOST}} --set database.username=${{secrets.DB_USERNAME}} --set database.password=${{secrets.DB_PASSWORD}} --set api.image.repository=${{secrets.API_IMAGE_URI}} --set frontend.image.repository=${{secrets.FRONTEND_IMAGE_URI}} + + + diff --git a/.gitignore b/.gitignore index 82d573a..8b13789 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -k8s/ -todo/ \ No newline at end of file + diff --git a/todo/.helmignore b/todo/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/todo/.helmignore @@ -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/ diff --git a/todo/Chart.yaml b/todo/Chart.yaml new file mode 100644 index 0000000..c5b4510 --- /dev/null +++ b/todo/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: todo +description: A Helm chart to deploy our todo app to 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: "1.16.0" diff --git a/todo/templates/api/database-migration-job.yaml b/todo/templates/api/database-migration-job.yaml new file mode 100644 index 0000000..3666eb4 --- /dev/null +++ b/todo/templates/api/database-migration-job.yaml @@ -0,0 +1,23 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: database-migration-job-{{ .Values.api.image.tag}} +spec: + ttlSecondsAfterFinished: 10 + template: + spec: + containers: + - name: database-migration-job + image: {{ .Values.api.image.repository}}:{{ .Values.api.image.tag}} + env: + - name: DB_HOST + value: {{ .Values.database.host}} + - name: DB_USERNAME + value: {{ .Values.database.username}} + - name: DB_PASSWORD + value: {{ .Values.database.password}} + - name: ENVIRONMENT + value: {{ .Values.environment}} + command: ["npm", "run", "migration:run", ] + restartPolicy: Never + backoffLimit: 1 \ No newline at end of file diff --git a/todo/templates/api/deployment.yaml b/todo/templates/api/deployment.yaml new file mode 100644 index 0000000..14ed4cb --- /dev/null +++ b/todo/templates/api/deployment.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: todo-api-deployment + labels: + app: todo + tier: api +spec: + replicas: 3 + selector: + matchLabels: + app: todo + tier: api + template: + metadata: + labels: + app: todo + tier: api + spec: + containers: + - name: todo-api + env: + - name: DB_HOST + value: {{ .Values.database.host}} + - name: DB_USERNAME + value: {{ .Values.database.username}} + - name: DB_PASSWORD + value: {{ .Values.database.password}} + - name: ENVIRONMENT + value: {{ .Values.environment}} + image: {{ .Values.api.image.repository}}:{{ .Values.api.image.tag}} + ports: + - containerPort: 80 \ No newline at end of file diff --git a/todo/templates/api/service.yaml b/todo/templates/api/service.yaml new file mode 100644 index 0000000..8e85003 --- /dev/null +++ b/todo/templates/api/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: todo-api-service + labels: + apps: todo + tier: api +spec: + selector: + app: todo + tier: api + + ports: + - protocol: TCP + port: 3000 + targetPort: 3000 \ No newline at end of file diff --git a/todo/templates/frontend/deployment.yaml b/todo/templates/frontend/deployment.yaml new file mode 100644 index 0000000..873baef --- /dev/null +++ b/todo/templates/frontend/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: todo-frontend-deployment + labels: + app: todo + tier: frontend +spec: + replicas: 3 + selector: + matchLabels: + app: todo + tier: frontend + template: + metadata: + labels: + app: todo + tier: frontend + spec: + containers: + - name: todo-frontend + image: {{ .Values.frontend.image.repository}}:{{ .Values.frontend.image.tag}} + ports: + - containerPort: 80 \ No newline at end of file diff --git a/todo/templates/frontend/service.yaml b/todo/templates/frontend/service.yaml new file mode 100644 index 0000000..55996b2 --- /dev/null +++ b/todo/templates/frontend/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: todo-frontend-service + labels: + apps: todo + tier: frontend +spec: + selector: + app: todo + tier: frontend + + ports: + - protocol: TCP + port: 80 + targetPort: 80 \ No newline at end of file diff --git a/todo/templates/ingress.yaml b/todo/templates/ingress.yaml new file mode 100644 index 0000000..dec4377 --- /dev/null +++ b/todo/templates/ingress.yaml @@ -0,0 +1,24 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: todo-ingress + +spec: + ingressClassName: nginx + rules: + - http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: todo-frontend-service + port: + number: 80 + - path: /api + pathType: Prefix + backend: + service: + name: todo-api-service + port: + number: 3000 \ No newline at end of file diff --git a/todo/values.yaml b/todo/values.yaml new file mode 100644 index 0000000..6e76067 --- /dev/null +++ b/todo/values.yaml @@ -0,0 +1,21 @@ +# Default values for todo. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +database: + host: "" + username: "" + password: "" + +environment: production + +api: + image: + repository: "" + tag: v2 + +frontend: + image: + repository: "" + tag: v2 +