Docker configuration Gitlab Jenkins java project automated deployment (1) Gitlab

Prerequisite environment

1、Docker

The lunux service memory has at least 4G, the installation tutorial is under Baidu

table of Contents

1. Installation

1. Pull the mirror

2. Create a host folder

3. Start

4. Adjust the time difference

5. Modify the configuration file gitlab.rb file

2. Create a code warehouse and upload code

1. Create a maven project

2. Then go to gitllab, first create a warehouse

3. Go back to the IDEA editor


1. Installation

1. Pull the mirror

docker pull gitlab/gitlab-ce:latest

2. Create a host folder

mkdir gitlab
mkdir gitlab/config
mkdir gitlab/data
mkdir gitlab/logs

3. Start

docker run -d --name gitlab --restart always -p 9798:443  -p 44:22  -p 9799:80 -v /gitlab/config:/etc/gitlab -v /gitlab/logs:/var/log/gitlab -v /gitlab/data:/var/opt/gitlab beginor/gitlab-ce

After the docker container is started, visit http://ip to enter the gitlab access interface. The first visit is to let us modify the administrator password, at least 8 characters

4. Adjust the time difference

docker cp /usr/share/zoneinfo/Asia/Shanghai gitlab:/etc/localtime

5. Modify the configuration file gitlab.rb file

cd /gitlab/config

vim  /gitlab/config/gitlab.rb

 

# 自己的服务器地址
external_url 'http://172.2.1.240:9799'

# 自己的服务器地址
gitlab_rails['gitlab_ssh_host'] = '172.2.1.240'
gitlab_rails['gitlab_shell_ssh_port'] = 22

PS: Because docker restart will cause the configuration of gitlab to become invalid, so the port number is added to the url

The same startup command needs to modify the port number

(First stop, then rm the container, restart first)

docker run -d --name gitlab --restart always -p 9798:443  -p 44:22  -p 9799:9799 -v /gitlab/config:/etc/gitlab -v /gitlab/logs:/var/log/gitlab -v /gitlab/data:/var/opt/gitlab beginor/gitlab-ce

PS: After Docker restarts, gitlab cannot start

2. Create a code warehouse and upload code

1. Create a maven project

Here is a simple springBoot project

pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>testgit</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>testgit</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!--web功能的起步依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

application.yml

server:
  port: 5555

Write a controller

package com.example.testgit;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * desciption
 * @Author junwei
 * @Date 2021/3/16 13:14
 */
@RestController
public class TestController {

    @GetMapping("/test")
    public String quick(){
        return "欢迎使用 一个简单的springBoot项目";
    }
}

start up:

 

2. Then go to gitllab, first create a warehouse

Create a warehouse, don’t operate other add files first, and then copy the address

3. Go back to the IDEA editor

The first upload needs to fill in the gitlab warehouse

After completion, there will be a prompt in the lower right corner of IDEA

Refresh the gitlab page, the code has been uploaded

 

The installation and use of docker-gitlab is basically the same. Other subsequent configurations need to be configured with jenkins

If you have any questions, please reply and discuss, this installation actually took some time

Docker configuration Gitlab Jenkins java project automated deployment (1) Gitlab

Docker configuration Gitlab Jenkins java project automated deployment (two) Jenkins

reference:

https://blog.csdn.net/wf19930209/article/details/80602459

Guess you like

Origin blog.csdn.net/qq_37203082/article/details/115031328