diff --git a/.dockerignore b/.dockerignore index 5171c54..475c70b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ node_modules -npm-debug.log \ No newline at end of file +npm-debug.log +dist \ No newline at end of file diff --git a/.github/workflows/dockerpublish.yml b/.github/workflows/dockerpublish.yml index ee9ac3a..3fd5af7 100644 --- a/.github/workflows/dockerpublish.yml +++ b/.github/workflows/dockerpublish.yml @@ -10,17 +10,40 @@ on: tags: - v* + # Run tests for any PRs. + pull_request: + env: IMAGE_NAME: wlan-cloud-ui jobs: + # Run tests. + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Run tests + run: | + if [ -f docker-compose.test.yml ]; then + docker-compose --file docker-compose.test.yml build + docker-compose --file docker-compose.test.yml run sut + else + docker build . --file Dockerfile + fi push: - + # Ensure test job passes before pushing image. + needs: test + runs-on: ubuntu-latest if: github.event_name == 'push' steps: - uses: actions/checkout@v2 + with: + ssh-key: ${{ secrets.NPM_REPO_AUTH_TOKEN }} - name: Build image run: docker build . --file Dockerfile --tag image diff --git a/.github/workflows/npm-build.yml b/.github/workflows/npm-build.yml deleted file mode 100644 index f842b91..0000000 --- a/.github/workflows/npm-build.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: NPM CI - TIP WLAN Cloud UI - -on: - push: - branches: [ master ] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - with: - node-version: '12.x' - registry-url: 'https://registry.npmjs.org' - - name: Cache node modules - uses: actions/cache@v1 - env: - cache-name: cache-node-modules - with: - path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - name: Install packages - run: npm install - - name: Build module - run: npm run build - - uses: actions/setup-node@v1 - with: - node-version: '12.x' - registry-url: 'https://tip.jfrog.io/artifactory/api/npm/tip-wlan-cloud-npm-repo/' - - name: Publish npm module into tip-wlan-cloud-npm-repo - run: npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_REPO_AUTH_TOKEN }} - diff --git a/Dockerfile b/Dockerfile index 2945808..473b655 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,12 @@ -FROM node:12 +# build environment +FROM node:13.12.0-alpine as build # Create app directory WORKDIR /app +# add `/app/node_modules/.bin` to $PATH +ENV PATH /app/node_modules/.bin:$PATH + # Install app dependencies # A wildcard is used to ensure both package.json AND package-lock.json are copied # where available (npm@5+) @@ -15,5 +19,11 @@ RUN npm ci --only=production # Bundle app source COPY . . -EXPOSE 3000 -CMD [ "npm", "start" ] \ No newline at end of file +CMD [ "npm", "run", "build" ] + +# production environment +FROM nginx:stable-alpine +COPY --from=dist /app/dist /usr/share/nginx/html +COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..ec76a60 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,3 @@ +sut: + build: . + command: npm test \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..758a646 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,17 @@ +server { + + listen 80; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + error_page 500 502 503 504 /50x.html; + + location = /50x.html { + root /usr/share/nginx/html; + } + +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6130d28..c7293c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13624,7 +13624,7 @@ } }, "wlan-cloud-ui-library": { - "version": "git+ssh://git@github.com/Telecominfraproject/wlan-cloud-ui-library.git#abbb7f2c8eaaeec30662331c0aed190be66c0de6", + "version": "git+ssh://git@github.com/Telecominfraproject/wlan-cloud-ui-library.git#00b7bb1f1bb1280549caceadd7a2b05dfbb28d39", "from": "git+ssh://git@github.com/Telecominfraproject/wlan-cloud-ui-library.git" }, "word-wrap": { diff --git a/package.json b/package.json index 34cc91b..2ae9126 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "antd": "^4.0.2", "apollo-boost": "^0.4.7", "clean-webpack-plugin": "^3.0.0", - "wlan-cloud-ui-library": "git+ssh://git@github.com/Telecominfraproject/wlan-cloud-ui-library.git", "graphql": "^14.6.0", "graphql-tag": "^2.10.3", "html-webpack-plugin": "^3.2.0", @@ -33,7 +32,8 @@ "react-dom": "^16.13.0", "react-helmet": "^5.2.1", "react-router-dom": "^5.1.2", - "terser-webpack-plugin": "^2.3.5" + "terser-webpack-plugin": "^2.3.5", + "wlan-cloud-ui-library": "git+ssh://git@github.com/Telecominfraproject/wlan-cloud-ui-library.git" }, "devDependencies": { "@babel/core": "^7.8.7",