diff --git a/.github/workflows/container.yml b/.github/workflows/build_dev.yml similarity index 75% rename from .github/workflows/container.yml rename to .github/workflows/build_dev.yml index 266862c..d062ce4 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/build_dev.yml @@ -1,8 +1,9 @@ -name: container +name: build dev + on: push: - # branches: - # - master + branches-ignore: + - master workflow_dispatch: jobs: @@ -53,11 +54,10 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - ### Set container tag to 'latest' if branch is master, and to $BRANCH_NAME otherwise - - if: ${{ env.BRANCH_NAME }} != 'master' - run: echo "CONTAINER_TAG=${{ env.BRANCH_NAME }}" >> $GITHUB_ENV - - if: ${{ env.BRANCH_NAME }} == 'master' - run: echo "CONTAINER_TAG=latest" >> $GITHUB_ENV + ### Set version + - run: echo "VERSION=0.1.${{github.run_number}}" >> $GITHUB_ENV + + - run: echo "CONTAINER_TAG=fluencelabs/dashboard:${{ env.VERSION }}${{ env.BRANCH_NAME }}" >> $GITHUB_ENV ### Build and push docker image - name: Build and push @@ -67,8 +67,6 @@ jobs: context: . file: ./caddy.Dockerfile push: true - tags: fluencelabs/dashboard:${{ env.CONTAINER_TAG }} + tags: ${{ env.CONTAINER_TAG }} - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} - -# docker commit --change='ENTRYPOINT ["caddy", "file-server", "--root", "/build", "--browse"]' caddy fluencelabs/fluence:demo \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 6bc71a9..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: deploy -on: - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Deploy dashboard@master to DigitalOcean via SSH - uses: appleboy/ssh-action@v0.1.3 - with: - HOST: ${{ secrets.DASHBOARD_HOST }} - USERNAME: ${{ secrets.DASHBOARD_USERNAME }} - KEY: ${{ secrets.DASHBOARD_SSHKEY }} - script: | - docker pull fluencelabs/dashboard:latest - docker rm -f dashboard - docker run -d --name dashboard -p443:443 -p80:80 -v caddy_data:/data fluencelabs/dashboard:latest diff --git a/.github/workflows/deploy_prod.yml b/.github/workflows/deploy_prod.yml new file mode 100644 index 0000000..d440394 --- /dev/null +++ b/.github/workflows/deploy_prod.yml @@ -0,0 +1,84 @@ +name: build and deploy prod + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + ### extract branch name + - name: Extract branch name + if: github.event_name != 'pull_request' + shell: bash + run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV + id: extract_branch + + - name: Extract branch name + if: github.event_name == 'pull_request' + run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV + + - uses: actions/checkout@v2 + + - name: Use Node.js 14 + uses: actions/setup-node@v1 + with: + node-version: 14 + + - run: npm install + - run: npm run prod + env: + CI: true + + ### Prepare docker & login to Dockerhub + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + ### Set version + - run: echo "VERSION=0.1.${{github.run_number}}" >> $GITHUB_ENV + + - run: echo "CONTAINER_TAG=fluencelabs/dashboard:latest,fluencelabs/dashboard:${{ env.VERSION }}" >> $GITHUB_ENV + + ### Build and push docker image + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + file: ./caddy.Dockerfile + push: true + tags: ${{ env.CONTAINER_TAG }} + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + + ### Deploy + - name: Deploy dashboard@master to DigitalOcean via SSH + uses: appleboy/ssh-action@v0.1.3 + with: + HOST: ${{ secrets.DASHBOARD_HOST }} + USERNAME: ${{ secrets.DASHBOARD_USERNAME }} + KEY: ${{ secrets.DASHBOARD_SSHKEY }} + script: | + docker pull fluencelabs/dashboard:${{ env.VERSION }} + docker rm -f dashboard + docker run -d --name dashboard -p443:443 -p80:80 -v caddy_data:/data fluencelabs/dashboard:${{ env.VERSION }} \ No newline at end of file diff --git a/Caddyfile b/Caddyfile index eb84de7..339ee9e 100644 --- a/Caddyfile +++ b/Caddyfile @@ -1,5 +1,4 @@ :8080, dash.fluence.dev { - log { output stderr format console @@ -8,6 +7,6 @@ tls alexey@fluence.one encode zstd gzip file_server - root * /bundle - try_files {path} /index.html + root * /dist + # try_files {path} /index.html } diff --git a/caddy.Dockerfile b/caddy.Dockerfile index 82e730a..b1841b3 100644 --- a/caddy.Dockerfile +++ b/caddy.Dockerfile @@ -1,6 +1,6 @@ FROM caddy WORKDIR / -COPY ./dist /bundle +COPY ./dist /dist COPY Caddyfile /Caddyfile #RUN printf '\n\ diff --git a/nginx.Dockerfile b/nginx.Dockerfile index 576b054..282bce6 100644 --- a/nginx.Dockerfile +++ b/nginx.Dockerfile @@ -1,2 +1,4 @@ FROM nginx +COPY ./nginx.conf /etc/nginx/conf.d/default.conf + COPY dist /usr/share/nginx/html diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..a61c1a9 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,9 @@ +server { + listen 80; + server_name frontend; + location / { + # This would be the directory where your React app's static files are stored at + root /usr/share/nginx/html; + try_files $uri /index.html; + } +} diff --git a/package.json b/package.json index 4c2ef7c..6a30e0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fluence-admin", - "version": "0.0.1", + "version": "0.1.0", "description": "", "main": "index.js", "scripts": { @@ -8,7 +8,7 @@ "start": "npm run dev", "dev": "webpack-dev-server --hot --colors --port 3000", "build": "webpack", - "prod": "webpack -p", + "prod": "webpack -p --mode production", "analyse": "elm-analyse -s -p 3001 -o", "compile-aqua": "aqua-cli --js -i ./aqua/ -o ./src/_aqua", "watch-aqua": "chokidar \"**/*.aqua\" -c \"npm run compile-aqua\"" diff --git a/src/index.js b/src/index.js index dd727a7..f7939b0 100644 --- a/src/index.js +++ b/src/index.js @@ -69,7 +69,7 @@ function event(name, peer, peers, identify, services, modules, blueprints) { /* eslint-enable */ (async () => { - setLogLevel('SILENT'); + setLogLevel('DEBUG'); const pid = await generatePeerId(); const flags = genFlags(pid.toB58String()); diff --git a/webpack.config.js b/webpack.config.js index 766ea71..320d1e9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,7 +1,7 @@ const path = require('path'); const { merge } = require('webpack-merge'); -const ClosurePlugin = require('closure-webpack-plugin'); +const TerserPlugin = require('terser-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const HTMLWebpackPlugin = require('html-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); @@ -137,19 +137,14 @@ if (MODE === 'development') { if (MODE === 'production') { module.exports = merge(common, { optimization: { + minimize: true, minimizer: [ - new ClosurePlugin( - { mode: 'STANDARD' }, - { - // compiler flags here - // - // for debugging help, try these: - // - // formatting: 'PRETTY_PRINT', - // debug: true - // renaming: false + new TerserPlugin({ + parallel: true, + terserOptions: { + // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions }, - ), + }), new OptimizeCSSAssetsPlugin({}), ], },