From 69cb2a355eed13416cd41b56553416ff166ceba4 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 30 Dec 2020 17:42:38 +0300 Subject: [PATCH] Implemented github actions (#27) Implemented github actions --- .github/workflows/pr_test.yml | 36 ++++++++++++++++ .github/workflows/release.yml | 77 +++++++++++++++++++++++++++++++++++ GitVersion.yml | 7 ++++ docker/Dockerfile | 8 ++++ docker/nginx.conf | 52 +++++++++++++++++++++++ 5 files changed, 180 insertions(+) create mode 100644 .github/workflows/pr_test.yml create mode 100644 .github/workflows/release.yml create mode 100644 GitVersion.yml create mode 100644 docker/Dockerfile create mode 100644 docker/nginx.conf diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml new file mode 100644 index 00000000..41739924 --- /dev/null +++ b/.github/workflows/pr_test.yml @@ -0,0 +1,36 @@ +name: PR + +on: + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js 12 + uses: actions/setup-node@v1 + with: + node-version: 12.x + + - name: Cache Node.js modules + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.OS }}-node- + ${{ runner.OS }}- + + - run: node --version + + - run: npm install + + - run: npm run build + + - run: npm test + env: + CI: true \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..07c51b64 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,77 @@ +name: Release + +on: + push: + tags: + - 'v*.*.*' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Fetch all history for all tags and branches + run: git fetch --prune --unshallow + + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v0.9.7 + with: + versionSpec: '5.x' + + - name: Use GitVersion + uses: gittools/actions/gitversion/execute@v0.9.7 + id: gitversion + + - name: Use Node.js 12 + uses: actions/setup-node@v1 + with: + node-version: 12.x + + - name: Cache Node.js modules + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.OS }}-node- + ${{ runner.OS }}- + + - run: node --version + + - run: npm install + + - run: npm run build + + - run: npm test + env: + CI: true + + - run: mv ./build ./docker/build + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USER }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./docker/ + file: ./docker/Dockerfile + builder: ${{ steps.buildx.outputs.name }} + push: true + tags: | + lifescience/med3web:latest + lifescience/med3web:${{ steps.gitversion.outputs.MajorMinorPatch }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} \ No newline at end of file diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 00000000..c6a66406 --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1,7 @@ +assembly-versioning-scheme: MajorMinorPatch +mode: ContinuousDeployment +next-version: 1.0.0 +branches: {} +ignore: + sha: [] +merge-message-formats: {} diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..bcceb04d --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,8 @@ +FROM nginx:1.19.3-alpine +RUN apk update && apk upgrade && \ + apk add --no-cache curl +WORKDIR /usr/share/nginx/html +COPY ./nginx.conf /etc/nginx/nginx.conf +COPY build . +HEALTHCHECK --interval=10s --timeout=3s \ + CMD curl -f http://localhost:4010/user-count/metrics || exit 1 \ No newline at end of file diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 00000000..149b562f --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,52 @@ +worker_processes auto; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; +worker_rlimit_nofile 8192; + +events { + worker_connections 4096; +} + +http { + include /etc/nginx/mime.types; + default_type text/html; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log off; + index index.html; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 15; + reset_timedout_connection on; + + open_file_cache max=200000 inactive=20s; + open_file_cache_valid 30s; + open_file_cache_min_uses 2; + open_file_cache_errors on; + + server { + listen 80; + listen [::]:80; + server_name _; + + gzip off; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html =404; + add_header Cache-Control "max-age=3600,private"; + } + location ~* \.(?:jpg|jpeg|gif|png|ttf|svg|ico)$ { + root /usr/share/nginx/html; + log_not_found off; + expires max; + add_header Cache-Control "max-age=86400,private"; + } + } +}