Key words: coding SpringBoot Docker

One, foreword

For Java projects, SpringBoot integrates Tomcat internally and is packaged as a JAR package, as long as the runtime environment allows. We can compare that

1, write the code after manual packaging 2, SSH connection, put the packaged project on the appropriate location, run

That’s fine, you might think. However, if there are 3-4 projects, one test environment and one production environment should be packaged according to the environment. Then you need to pack it 6-8 times, which is laborious and error-prone. Use steps after continuous integration:

2. After receiving coding, it is packaged into different environments and accessible after waiting for some time

This is convenient because every submission is packaged, and the more projects there are, the more persistent integration becomes valuable. The cost of learning in the early stage is relatively high and difficult to understand.


Second, preparation

1, registeredcoding

As you can see, open basic functions are free, unlimited number of members. This is much better than the code cloud. I won’t go over the basic registration, just follow the instructions.



2. Basic coding Settings

  1. Establishing the project

  1. Go to the project -> Build the code repository

  1. Import a sample project into the repository gitee.com/TheOldMan/s… The project is a hello method, take this project test.

  1. Import a project from outside and copy the example project address above




3. Coding persistence integration Settings

1. Continuous Integration Build Plan Build plan

2. Select Java + Spring + Docker

3. Name of the build plan (you can change it if you want)



4. Select the repository to build & compile build command line



5. Build Docker image

6. Create Dockerfile in the project

I have done this step for you in the file, but I want to emphasize that this step is very important

# Java environment
FROM java:8u111

Define the working directory
WORKDIR /app
Copy everything in the project to the working directory (app)
COPY.
Assign the packaged file to the app below for easy operation
ADD target/*.jar /app/app.jar
Change the time zone of the container
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone

EXPOSE 8080
ENTRYPOINT ["java"."-jar"."/app/app.jar"]
Copy the code

7. Build/select a product library

If you don’t have one, choose one



8. Configure the deployment to the remote service

Note:CODING credentials are entered into the tutorial



9. Uncheck and click OK

There’s something else you have to do, not build






Set the environment parameters before running

1. Go to the Build plan Settings page



2. Set trigger rules





3. Jump to the wip and copy the wIP login name and password

I’ll copy everything, and it’ll be useful later



4. Configure environment variables







5. Main implementation related to Docker in configuration

Persistent integration involves a lot of things and is a test for yourself. The configuration file doesn’t need to be modified anymore, you need to make sure that ports on your machine/cloud server are open and not occupied.Remember to save



Start building & testing

1. Click Build

2. Whether the test is successful

Yes 😁





6. Recommendation of relevant articles

Finch: Coding platform Vue project continues to integrate into Tencent Cloud Linux server