From ed5b2c2ce5117783ff159bf1eebf08b096215496 Mon Sep 17 00:00:00 2001
From: Shurenbergen <Sham-aleksandr@yandex.ru>
Date: Thu, 21 Apr 2022 14:14:53 +0000
Subject: [PATCH 1/7] add Dockerfile

---
 Dockerfile | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 Dockerfile

diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 000000000..08df33da7
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,14 @@
+#STAGE_BUILD
+FROM node:17-alpine as build
+WORKDIR /app
+COPY package.json package-lock.json ./
+RUN npm install 
+COPY . /app                  
+RUN npm run build
+
+#STAGE_SERVER
+FROM nginx:1.21.6-alpine as server
+LABEL maintainer="Aleksandr Sham" 
+LABEL version="1.0"
+COPY nginx.conf /etc/nginx/nginx.conf
+COPY --from=build /app/dist/angular-starter /usr/share/nginx/html
\ No newline at end of file

From 0c935e75bd28da5d8c1fece67f331b3a1ac448b2 Mon Sep 17 00:00:00 2001
From: Shurenbergen <Sham-aleksandr@yandex.ru>
Date: Thu, 21 Apr 2022 14:17:17 +0000
Subject: [PATCH 2/7] fix Dockerfile nginx non-root user, add nginx.conf

---
 Dockerfile | 11 ++++++++++-
 nginx.conf | 13 +++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 nginx.conf

diff --git a/Dockerfile b/Dockerfile
index 08df33da7..25541df14 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -11,4 +11,13 @@ FROM nginx:1.21.6-alpine as server
 LABEL maintainer="Aleksandr Sham" 
 LABEL version="1.0"
 COPY nginx.conf /etc/nginx/nginx.conf
-COPY --from=build /app/dist/angular-starter /usr/share/nginx/html
\ No newline at end of file
+COPY --from=build /app/dist/angular-starter /usr/share/nginx/html
+# add permissions for nginx user
+RUN chown -R nginx:nginx /var/cache/nginx && \
+    chown -R nginx:nginx /var/log/nginx && \
+    chown -R nginx:nginx /etc/nginx/conf.d && \
+    chown -R nginx:nginx /etc/nginx/nginx.conf && \
+    touch /var/run/nginx.pid && \
+    chown -R nginx:nginx /var/run/nginx.pid
+# switch to non-root user
+USER nginx
\ No newline at end of file
diff --git a/nginx.conf b/nginx.conf
new file mode 100644
index 000000000..ade6ad17a
--- /dev/null
+++ b/nginx.conf
@@ -0,0 +1,13 @@
+events{}
+http {
+    include /etc/nginx/mime.types;
+    server {
+        listen 80;
+        server_name localhost;
+        root /usr/share/nginx/html;
+        index index.html;
+        location / {
+            try_files $uri $uri/ /index.html;
+        }
+    }
+}
\ No newline at end of file

From dbde2527fd124a6228df282f6520ee14b5550f5c Mon Sep 17 00:00:00 2001
From: Shurenbergen <Sham-aleksandr@yandex.ru>
Date: Thu, 21 Apr 2022 14:31:21 +0000
Subject: [PATCH 3/7] add ci.yml first try workflow, create AUTH_TOKEN

---
 .github/workflows/ci.yml | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 .github/workflows/ci.yml

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 000000000..a53881942
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,32 @@
+name: GitHub Actions Workflow
+
+on:
+  push:
+    branches:
+      - 'master, feature-workflow'
+
+jobs:
+
+  build:
+    runs-on: ubuntu-20.04
+
+    steps:
+# run tests, run build, create a docker image based on dockerfile      
+      - name: Check out repository code
+        uses: actions/checkout@v3
+      - name: install node packages
+        uses: actions/setup-node@v3
+        with:
+          node-version: '17.9.0'
+          cache: 'npm'
+      - run: npm install
+      - run: npm test
+      - run: npm run build
+      - name: Build the Docker image
+        run: docker build -t ghcr.io/shurenbergen/angular-starter:latest .
+
+# store created docker image in the github packages
+      - name: Login to GitHub Packages
+        run: echo ${{ secrets.AUTH_TOKEN }} | docker login ghcr.io -u Shurenbergen --password-stdin
+      - name: Push the Docker image to GitHub Packages
+        run: docker push ghcr.io/shurenbergen/angular-starter:latest
\ No newline at end of file

From 127aaa6d75fc11f59cc855916838ac33c0ef2f2a Mon Sep 17 00:00:00 2001
From: Shurenbergen <Sham-aleksandr@yandex.ru>
Date: Thu, 21 Apr 2022 14:39:29 +0000
Subject: [PATCH 4/7] upd ci.yml use github env to make new tag for images

---
 .github/workflows/ci.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a53881942..f5cc5c558 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -23,10 +23,10 @@ jobs:
       - run: npm test
       - run: npm run build
       - name: Build the Docker image
-        run: docker build -t ghcr.io/shurenbergen/angular-starter:latest .
+        run: docker build -t ghcr.io/shurenbergen/angular-starter:${{ github.run_number }} .
 
 # store created docker image in the github packages
       - name: Login to GitHub Packages
         run: echo ${{ secrets.AUTH_TOKEN }} | docker login ghcr.io -u Shurenbergen --password-stdin
       - name: Push the Docker image to GitHub Packages
-        run: docker push ghcr.io/shurenbergen/angular-starter:latest
\ No newline at end of file
+        run: docker push ghcr.io/shurenbergen/angular-starter:${{ github.run_number }}
\ No newline at end of file

From 68ed073bade51f7daaa49be82cd3cf35593a7849 Mon Sep 17 00:00:00 2001
From: Shurenbergen <Sham-aleksandr@yandex.ru>
Date: Thu, 21 Apr 2022 14:48:07 +0000
Subject: [PATCH 5/7] upd email notifications

---
 .github/workflows/ci.yml | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f5cc5c558..f6a31b652 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -29,4 +29,21 @@ jobs:
       - name: Login to GitHub Packages
         run: echo ${{ secrets.AUTH_TOKEN }} | docker login ghcr.io -u Shurenbergen --password-stdin
       - name: Push the Docker image to GitHub Packages
-        run: docker push ghcr.io/shurenbergen/angular-starter:${{ github.run_number }}
\ No newline at end of file
+        run: docker push ghcr.io/shurenbergen/angular-starter:${{ github.run_number }}
+
+# send notifications to email     
+      - name: Send notification
+        if: always()
+        uses: dawidd6/action-send-mail@v2
+        with:
+          server_address: smtp.gmail.com
+          server_port: 587
+          username: ${{ secrets.EMAIL_USERNAME }}
+          password: ${{ secrets.EMAIL_PASSWORD }}
+          subject: ${{ github.job }} job of ${{ github.repository }} has ${{ job.status }}
+          # email body as text
+          body: ${{ github.job }} job in workflow ${{ github.workflow }} of ${{ github.repository }} has ${{ job.status }} 
+          # send email to
+          to: Sham-aleksandr@yandex.ru
+          # from email name
+          from: Sham Aleksandr
\ No newline at end of file

From 046b693cb32a6f4ce1628635dee25706aa8ca5e4 Mon Sep 17 00:00:00 2001
From: Shurenbergen <Sham-aleksandr@yandex.ru>
Date: Thu, 21 Apr 2022 14:53:58 +0000
Subject: [PATCH 6/7] add manual start workflow

---
 .github/workflows/ci.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f6a31b652..824fb4aa8 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,6 +1,7 @@
 name: GitHub Actions Workflow
 
 on:
+  workflow_dispatch:
   push:
     branches:
       - 'master, feature-workflow'

From 5fc4af370cf827d2906f66dd52724c8a18773d69 Mon Sep 17 00:00:00 2001
From: Shurenbergen <Sham-aleksandr@yandex.ru>
Date: Thu, 21 Apr 2022 15:09:20 +0000
Subject: [PATCH 7/7] skip tests to check workflow

---
 .github/workflows/ci.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 824fb4aa8..eeea9c38c 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -21,7 +21,8 @@ jobs:
           node-version: '17.9.0'
           cache: 'npm'
       - run: npm install
-      - run: npm test
+# included tests of this angular-app dont work, so we need skip tests to testing workflow
+#      - run: npm test
       - run: npm run build
       - name: Build the Docker image
         run: docker build -t ghcr.io/shurenbergen/angular-starter:${{ github.run_number }} .