From d736033c75e84818d5e9906ee31ae61856b4072c Mon Sep 17 00:00:00 2001 From: Konrad Chmielecki <6963493+3mam@users.noreply.github.com> Date: Mon, 8 Jan 2024 11:05:20 +0100 Subject: [PATCH 1/5] creating file: .dockerignore --- .dockerignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ac69008 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +Dockerfile +charts/ +bin/ +obj/ From ffacc1be93a8de4b08cbd7dc07a6a32f8ed076b0 Mon Sep 17 00:00:00 2001 From: Konrad Chmielecki <6963493+3mam@users.noreply.github.com> Date: Mon, 8 Jan 2024 11:05:20 +0100 Subject: [PATCH 2/5] creating file: Dockerfile --- Dockerfile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5c8b708 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS builder +WORKDIR /app + +# caches restore result by copying csproj file separately +COPY *.csproj . +RUN dotnet restore + +COPY . . +RUN dotnet publish --output /app/ --configuration Release --no-restore +RUN sed -n 's:.*\(.*\).*:\1:p' *.csproj > __assemblyname +RUN if [ ! -s __assemblyname ]; then filename=$(ls *.csproj); echo ${filename%.*} > __assemblyname; fi + +# Stage 2 +FROM mcr.microsoft.com/dotnet/aspnet:6.0 +WORKDIR /app +COPY --from=builder /app . + +ENV PORT 5000 +EXPOSE 5000 + +ENTRYPOINT dotnet $(cat /app/__assemblyname).dll --urls "http://*:5000" From 6d8f2b83b6ef094fcd8a5f8a39ca78a08ba5ed63 Mon Sep 17 00:00:00 2001 From: Konrad Chmielecki <6963493+3mam@users.noreply.github.com> Date: Mon, 8 Jan 2024 11:05:21 +0100 Subject: [PATCH 3/5] creating file: manifests/deployment.yaml --- manifests/deployment.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 manifests/deployment.yaml diff --git a/manifests/deployment.yaml b/manifests/deployment.yaml new file mode 100644 index 0000000..3f1a0e0 --- /dev/null +++ b/manifests/deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: flow + labels: + app: flow + namespace: namespace-workflow-1704708220380 +spec: + replicas: 1 + selector: + matchLabels: + app: flow + template: + metadata: + labels: + app: flow + spec: + containers: + - name: flow + image: k8stestfoo.azurecr.io/image-workflow-1704708220380:latest + ports: + - containerPort: 5000 \ No newline at end of file From c05d1cef67845e68493f99d7db20fd15bc11151e Mon Sep 17 00:00:00 2001 From: Konrad Chmielecki <6963493+3mam@users.noreply.github.com> Date: Mon, 8 Jan 2024 11:05:22 +0100 Subject: [PATCH 4/5] creating file: manifests/service.yaml --- manifests/service.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 manifests/service.yaml diff --git a/manifests/service.yaml b/manifests/service.yaml new file mode 100644 index 0000000..aa6ca61 --- /dev/null +++ b/manifests/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: flow + namespace: namespace-workflow-1704708220380 +spec: + type: LoadBalancer + selector: + app: flow + ports: + - protocol: TCP + port: 5000 + targetPort: 5000 \ No newline at end of file From 90cb8cf12d15dc43f922a06f2722aa5a5a4afa96 Mon Sep 17 00:00:00 2001 From: Konrad Chmielecki <6963493+3mam@users.noreply.github.com> Date: Mon, 8 Jan 2024 11:05:22 +0100 Subject: [PATCH 5/5] creating file: .github/workflows/flow.yaml --- .github/workflows/flow.yaml | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/flow.yaml diff --git a/.github/workflows/flow.yaml b/.github/workflows/flow.yaml new file mode 100644 index 0000000..3e5e487 --- /dev/null +++ b/.github/workflows/flow.yaml @@ -0,0 +1,65 @@ +name: flow +"on": + push: + branches: + - main + workflow_dispatch: {} +env: + ACR_RESOURCE_GROUP: k8s + AZURE_CONTAINER_REGISTRY: k8stestfoo + CLUSTER_NAME: test-cluster + CLUSTER_RESOURCE_GROUP: k8s + CONTAINER_NAME: image-workflow-1704708220380 + 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@92a5484dfaf04ca78a94597f4f19fea633851fa2 + 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@92a5484dfaf04ca78a94597f4f19fea633851fa2 + 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-1704708220380