diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..eeea9c38c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,51 @@ +name: GitHub Actions Workflow + +on: + workflow_dispatch: + 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 +# 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 }} . + +# 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:${{ 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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..25541df14 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +#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 +# 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