Recently, I plan to deploy a front-end application (online documentation). I found that Docker is very convenient, you don’t need to be familiar with Nginx, Linux can easily container a front-end application. Implement a simple CI/CD process with DaoCloud.

Environment to prepare

Before starting the application, we need to prepare the environment.

  • The node environment
  • Prepare a server
  • Making account

Create a project

We chose Vuepress to help us build a site.

  • Let’s create a repO on Github. Such as my – programming – the dock.
  • See vuepress Quick Start Configuration

The next step is to create the Dockerfile configuration file and configure it.

Nginx RUN apt-get update \ && apt-get install -y nginx # specify WORKDIR /app /app/ # EXPOSE 80 # 1 Install dependencies # 2. Build package # 3. Copy files from dist directory to nginx directory # 4. Delete the work files in the directory Reduce the image size RUN NPM install - registry=https://registry.npm.taobao.org \ && NPM RUN docs: build \ && cp -r Docs /.vuepress/dist/* /var/ WWW/HTML \ && rm -rf /app # start nginx CMD ["nginx", "-g", "daemon off;"]Copy the code
  • Upload to Github.

Configuration DaoCloud

DaoCloud was founded at the end of 2014. It is a container cloud platform service provider, providing various cloud computing platform services centering on Docker technology, including Docker Hub image service, Docker native application operation and management platform, open source technology community activities, etc.

Our entire CI/CD process is done using DaoCloud.

  • Log in to DaoCloud via Github.
  • Go create your project

  • Each project has a pipeline that can be configured as needed.

If we don’t have a console in the early stage, we don’t need to configure the release phase, which we’ll talk about later. In addition, we need to note that there is one option for process editing to be aware of: triggering conditions. The branch is the code branch, and the tag is git tag.

  • We can manually trigger the build once.

  • Add our host in cluster management.

Here you just need to install Docker on your server and execute the corresponding shell to install the host monitor. s

  • We can choose to deploy once manually

  • The deployment was successful

Visit http://182.61.39.64:32772/ success.

Automated publishing

We have the whole process running now, but it’s not automated enough.

We ideally wanted one-click auto-deployment: so we chose to tag as the build trigger.

  • Configure the CI/CD process and add a release process in the release process.

At the same time, trigger conditions for all processes are changed to labels.

  • Write node script to automatically tag.

After the selection is complete, it comes with the tag and push Github, triggering CI/CD process! .

Ps: code repository address. Commit test stepped on some pits a bit dirty, subsequent merge.

reference

  • Build front-end continuous integration development environment based on Docker

Welcome to my public number XYZ programming diary