This is the third day of my participation in the More text Challenge. For details, see more text Challenge
GiteaDroneCi
The following installation and operations are performed in Docker mode
1. Install gitea
1. Install gitea
docker run -d --privileged=true --name=gitea -p 10022:22 -p 10080:3000 gitea/gitea
Copy the code
Access localhost:10080. The interactive installation page is displayed
Modify the item | value |
---|---|
Based on the URL | Host IP: 10080 |
SSH service domain name | The host IP |
The remaining options can be default, you can modify. |
2. Create a test project and push it to the repository through HTTP.
I created a random SpringBoot Web project here.
3. Generate GiteaOauth
In the upper right corner of gitea, choose Settings > Application > Create Application
Client id: 5667 df0 b0f2-2-497 - d - 8 c31 microcomputer to 37 e43f178a26 client secret key: heaoKnIbKmGB3QGpE7NR5QLczaYtwlXA5PYweH3kcPp1Copy the code
Redirect to the DRONE’s URL
# I drone configuration here is that the port 80 http://192.168.31.79/loginCopy the code
Generate an RPC secret key
openssl rand -hex 16
Copy the code
3. Install the drone
Docker run \ - v/var/run/docker. The sock: / var/run/docker. The sock \ - \ env = DRONE_GITEA_SERVER = http://192.168.31.79:10080/ --env=DRONE_GITEA_CLIENT_ID=5667b0f2-2df0-497d-8c31-37e43f178a26 \ --env=DRONE_GITEA_CLIENT_SECRET=heaoKnIbKmGB3QGpE7NR5QLczaYtwlXA5PYweH3kcPp1 \ --env=DRONE_RPC_SECRET=dd6fed184d56520b5c72ff652f941eb2 \ --env=DRONE_USER_CREATE=username:root,admin:true \ --env=DRONE_SERVER_HOST=192.168.31.79 \ --env=DRONE_SERVER_PROTO= HTTP \ --publish=80:80 \ --publish=443:443 \ --restart=always \ --detach=true \ --name=drone \ drone/droneCopy the code
The port number and so on can be changed to not occupied, sock must be mounted, because drone needs to rely on the host docker, can cache images and so on.
key | value |
---|---|
DRONE_GITEA_SERVER | GiteaServerUrl |
DRONE_GITEA_CLIENT_ID | Id of the application client |
DRONE_GITEA_CLIENT_SECRET | The secret client key of the application |
DRONE_RPC_SECRET | The Rpc secret key applied |
DRONE_USER_CREATE | Administrator user name Corresponds to the user name of Gitea |
DRONE_SERVER_HOST | IP + port of the DroneServer |
Reference: docs. Drone. IO/server/prov…
3. Install the runner
Docker run - d \ - v/var/run/docker. The sock: / var/run/docker. The sock \ \ - e - e DRONE_RPC_PROTO = HTTP DRONE_RPC_HOST = 192.168.31.79 \ -e DRONE_RPC_SECRET=dd6fed184d56520b5c72ff652f941eb2 \ -e DRONE_RUNNER_CAPACITY=2 \ -e DRONE_RUNNER_NAME=drone-runner \ -p 3000:3000 \ --restart always \ --name runner \ drone/drone-runner-dockerCopy the code
key | value |
---|---|
DRONE_RPC_HOST | IP + port of the drone |
DRONE_GITEA_CLIENT_ID | Id of the application client |
DRONE_RPC_SECRET | The Rpc secret key applied |
Reference: docs. Drone. IO/runner/dock…
4. Install the Private image repository (Nexus)
docker run -d -p 7081:8081 -p 7082:8082 -p 7083:8083 -p 5000:5000 --name nexus3 sonatype/nexus3
Copy the code
Follow the instructions to obtain the initial password after login, and change the passwordCreate a Docker (hosts) image repository as shown above, and add Docker permissions through Realms
#Docker. json adds the repository"Insecure - registries:" [] "192.168.31.79:5000"Copy the code
I’m not persisting it here, so you can change it if you want to use it yourself, so pay attention to the port number.
5. Configuration Dockerfile
Create a Dockerfile file in the root of your project
FROM openjdk:8
RUN ls
ADD /target/*.jar app.jar
ENTRYPOINT [ "sh"."-c"."java -jar /app.jar" ]
Copy the code
6. Configuration. Drone. Yml
Create one in the project’s root directory. Drone.yml file (there is a. Don’t forget)
kind: pipeline
name: run # Pipeline name
type: docker # type
steps:
- name: Packaging & unit testing # Step name
image: Maven: 3.6.2 - JDK - 8 # Image used for this step
commands:
- mvn clean package # Command executed in mirroring
volumes:
- name: cache
path: /root/.m2 Avoid having to re-download the JAR every time
when:
branch: master # branch
event: [ push ] # Trigger event
- name: Packaging image
image: plugins/docker # Build image of docker image
settings:
repo: 192.16831.79.:5000/mytest/test # Local image repository, the default I built here does not require a password
tags: latest # version
registry: 192.16831.79.: 5000
username: admin User name for # Nexus
password: 123123 # the nexus of the password
insecure: true The default is HTTPS
tags: latest
volumes:
- name: docker
path: /var/run/docker.sock # Mount sock
when:
branch: master
event: [ push ]
volumes:
- name: cache
host:
path: /Users/yujian/.m2 # host directory
- name: docker
host:
path: /var/run/docker.sock # Host docker.sock file
Copy the code
7. Authorize the drone
Access to the DRONE’s IP can get gITEA authorization, click the authorization will automatically add Webhook.
8. Activate the project
Activate the item in Drone -> Setting and enable Trusted to trust the item
9. Submitting code triggers the pipeline
If both are green, the construction is successful. Here, after the drone is executed, it will call System prune -f to clean up the unstarted images and containers. This machine must be operated with caution
10. Summary
All drone steps are in a workspace and can be directly passed down. For example, the JAR package directory in the build phase is
/ drone/SRC/target/SpringBootTestDemo - 0.0.1 - the SNAPSHOT. The jar
Copy the code
Other containers use a directory for. / target/SpringBootTestDemo – 0.0.1 – the SNAPSHOT. Jar available
Take a look at the source of plugins/ Docker
if p.Cleanup {
cmds = append(cmds, commandRmi(p.Build.Name)) // docker rmi
cmds = append(cmds, commandPrune()) // docker system prune -f
}
Dryrun: c.Bool("dry-run"),
Cleanup: c.BoolT("docker.purge"), # change to purge = in Settings configurationfalseLogin: docker.login {Registry: c.tring ("docker.registry"),
Username: c.String("docker.username"),
Password: c.String("docker.password"),
Email: c.String("docker.email"),
Config: c.String("docker.config"),},Copy the code
The problem
If it is found that clicking the authorization redirection to login has timed out and no response, it is necessary to check whether Docker Network has a network beginning with drone to kill. At that time, the deleted unexpectedly did not record the IP and reason, and it has not been reproduced temporarily
Drone integrates with Sonar and deployment steps