diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..843dec4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +charts/ diff --git a/.github/workflows/Demo.yaml b/.github/workflows/Demo.yaml new file mode 100644 index 0000000..7898941 --- /dev/null +++ b/.github/workflows/Demo.yaml @@ -0,0 +1,65 @@ +name: Demo +"on": + push: + branches: + - main + workflow_dispatch: {} +env: + ACR_RESOURCE_GROUP: my-resource-group + AZURE_CONTAINER_REGISTRY: acrworkflow1685610716580 + CLUSTER_NAME: my-aks-cluster + CLUSTER_RESOURCE_GROUP: my-resource-group + CONTAINER_NAME: image-workflow-1685610716580 + DEPLOYMENT_MANIFEST_PATH: | + manifests/deployment.yaml + manifests/service.yaml +jobs: + buildImage: + permissions: + contents: read + id-token: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: azure/login@v1.4.3 + name: Azure login + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + - name: Build and push image to ACR + run: az acr build --image ${{ env.CONTAINER_NAME }}:${{ github.sha }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.ACR_RESOURCE_GROUP }} -f Dockerfile ./ + deploy: + permissions: + actions: read + contents: read + id-token: write + runs-on: ubuntu-latest + needs: + - buildImage + steps: + - uses: actions/checkout@v3 + - uses: azure/login@v1.4.3 + name: Azure login + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + - uses: azure/use-kubelogin@v1 + name: Set up kubelogin for non-interactive login + with: + kubelogin-version: v0.0.25 + - uses: azure/aks-set-context@v3 + name: Get K8s context + with: + admin: "false" + cluster-name: ${{ env.CLUSTER_NAME }} + resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }} + use-kubelogin: "true" + - uses: Azure/k8s-deploy@v4 + name: Deploys application + with: + action: deploy + images: ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} + manifests: ${{ env.DEPLOYMENT_MANIFEST_PATH }} + namespace: namespace-workflow-1685610716580 diff --git a/.github/workflows/demo-app.yaml b/.github/workflows/demo-app.yaml new file mode 100644 index 0000000..0932ef7 --- /dev/null +++ b/.github/workflows/demo-app.yaml @@ -0,0 +1,65 @@ +name: demo-app +"on": + push: + branches: + - main + workflow_dispatch: {} +env: + ACR_RESOURCE_GROUP: my-resource-group + AZURE_CONTAINER_REGISTRY: acrworkflow1685611537556 + CLUSTER_NAME: my-aks-cluster + CLUSTER_RESOURCE_GROUP: my-resource-group + CONTAINER_NAME: image-workflow-1685611537556 + DEPLOYMENT_MANIFEST_PATH: | + manifests/deployment.yaml + manifests/service.yaml +jobs: + buildImage: + permissions: + contents: read + id-token: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: azure/login@v1.4.3 + name: Azure login + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + - name: Build and push image to ACR + run: az acr build --image ${{ env.CONTAINER_NAME }}:${{ github.sha }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.ACR_RESOURCE_GROUP }} -f Dockerfile ./src + deploy: + permissions: + actions: read + contents: read + id-token: write + runs-on: ubuntu-latest + needs: + - buildImage + steps: + - uses: actions/checkout@v3 + - uses: azure/login@v1.4.3 + name: Azure login + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + - uses: azure/use-kubelogin@v1 + name: Set up kubelogin for non-interactive login + with: + kubelogin-version: v0.0.25 + - uses: azure/aks-set-context@v3 + name: Get K8s context + with: + admin: "false" + cluster-name: ${{ env.CLUSTER_NAME }} + resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }} + use-kubelogin: "true" + - uses: Azure/k8s-deploy@v4 + name: Deploys application + with: + action: deploy + images: ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} + manifests: ${{ env.DEPLOYMENT_MANIFEST_PATH }} + namespace: namespace-workflow-1685611537556 diff --git a/.github/workflows/github.yaml b/.github/workflows/github.yaml new file mode 100644 index 0000000..e7fee86 --- /dev/null +++ b/.github/workflows/github.yaml @@ -0,0 +1,65 @@ +name: github +"on": + push: + branches: + - main + workflow_dispatch: {} +env: + ACR_RESOURCE_GROUP: exampleaks1registry_group + AZURE_CONTAINER_REGISTRY: exampleaks1registry + CLUSTER_NAME: example-aks1 + CLUSTER_RESOURCE_GROUP: example-resources + CONTAINER_NAME: image-workflow-1685511374382 + DEPLOYMENT_MANIFEST_PATH: | + ./manifests/deployment-1.yml + ./manifests/deployment.yml +jobs: + buildImage: + permissions: + contents: read + id-token: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: azure/login@v1.4.3 + name: Azure login + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + - name: Build and push image to ACR + run: az acr build --image ${{ env.CONTAINER_NAME }}:${{ github.sha }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.ACR_RESOURCE_GROUP }} -f ./Dockerfile ./ + deploy: + permissions: + actions: read + contents: read + id-token: write + runs-on: ubuntu-latest + needs: + - buildImage + steps: + - uses: actions/checkout@v3 + - uses: azure/login@v1.4.3 + name: Azure login + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + - uses: azure/use-kubelogin@v1 + name: Set up kubelogin for non-interactive login + with: + kubelogin-version: v0.0.25 + - uses: azure/aks-set-context@v3 + name: Get K8s context + with: + admin: "false" + cluster-name: ${{ env.CLUSTER_NAME }} + resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }} + use-kubelogin: "true" + - uses: Azure/k8s-deploy@v4 + name: Deploys application + with: + action: deploy + images: ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} + manifests: ${{ env.DEPLOYMENT_MANIFEST_PATH }} + namespace: namespace-workflow-1685511374382 diff --git a/.github/workflows/sync_codeowners_to_devops.yml b/.github/workflows/sync_codeowners_to_devops.yml new file mode 100644 index 0000000..763fbac --- /dev/null +++ b/.github/workflows/sync_codeowners_to_devops.yml @@ -0,0 +1,31 @@ +name: Sync CODEOWNERS to DevOps Repo + +on: + push: + paths: + - CODEOWNERS + +jobs: + sync-codeowners: + runs-on: ubuntu-latest + + steps: + - name: Checkout Source Repository + uses: actions/checkout@v2 + + - name: Sync CODEOWNERS to DevOps Repo + env: + GITHUB_TOKEN: ${{ secrets.TARGET_REPOS_PAT }} + run: | + # Clone the devops repo + git clone https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/edwinkullu/Terraform.git + + # Copy CODEOWNERS to the devops repo + cp CODEOWNERS Terraform/.github/CODEOWNERS + + cd devops-repo + git add .github/CODEOWNERS + git commit -m "Update CODEOWNERS from repo2" + git push + cd .. + rm -rf devops-repo diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ + diff --git a/Dockerfile b/Dockerfile index ae2dff7..b9132c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,11 @@ -FROM node:8 +FROM node:19 +ENV PORT 3000 +EXPOSE 3000 -# Create app directory +RUN mkdir -p /usr/src/app WORKDIR /usr/src/app - -# Install app dependencies -# A wildcard is used to ensure both package.json AND package-lock.json are copied -# where available (npm@5+) -COPY package*.json ./ - +COPY package.json . RUN npm install -# If you are building your code for production -# RUN npm install --only=production - -# Bundle app source COPY . . -EXPOSE 8080 -CMD [ "npm", "start" ] +CMD ["npm", "start"] diff --git a/manifests/deployment.yaml b/manifests/deployment.yaml new file mode 100644 index 0000000..4a8e154 --- /dev/null +++ b/manifests/deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: demo-app + labels: + app: demo-app + namespace: namespace-workflow-1685611537556 +spec: + replicas: 1 + selector: + matchLabels: + app: demo-app + template: + metadata: + labels: + app: demo-app + spec: + containers: + - name: demo-app + image: acrworkflow1685611537556.azurecr.io/image-workflow-1685611537556:latest + ports: + - containerPort: 3000 \ No newline at end of file diff --git a/manifests/service.yaml b/manifests/service.yaml new file mode 100644 index 0000000..662325e --- /dev/null +++ b/manifests/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: demo-app + namespace: namespace-workflow-1685611537556 +spec: + type: LoadBalancer + selector: + app: demo-app + ports: + - protocol: TCP + port: 3000 + targetPort: 3000 \ No newline at end of file