docker搭建gogsgit源码管理

2021-09-29  本文已影响0人  liurongming

docker 搭建gogsgit

docker pull gogs/gogs
[root@itdev7001 ~]# docker pull gogs/gogs
Using default tag: latest
Trying to pull repository docker.io/gogs/gogs ...
latest: Pulling from docker.io/gogs/gogs
ddad3d7c1e96: Pull complete
98bfa715d475: Pull complete
41833e5090f7: Pull complete
0eaa2e62e844: Pull complete
099dafadbd3c: Pull complete
a65e863c4361: Pull complete
6f047877c3f9: Pull complete
Digest: sha256:1c42233010268ef058cd98ca42e4940d20ff2276f01a7db83f9114b1dd8e17ed
Status: Downloaded newer image for docker.io/gogs/gogs:latest

查看镜像

[root@localhost ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
docker.io/redis       latest              08502081bff6        2 weeks ago         105 MB
docker.io/gogs/gogs   0.12                4075c4a42f12        9 months ago        92.6 MB
[root@localhost ~]#
安装镜像
docker run -d --name=gogs --restart=always -p 2222:22 -p 9030:3000 -v /usr/local/docker/gogs:/data gogs/gogs
打卡端口
firewall-cmd --zone=public --add-port=9030/tcp --permanent  
firewall-cmd --zone=public --add-port=2222/tcp --permanent  
firewall-cmd --reload

查看所有容器

# docker ps -a 

[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                    NAMES
630aa3447f9b        gogs/gogs:0.12      "/app/gogs/docker/..."   2 minutes ago       Exited (2) 2 minutes ago                            gogs
aa1c2b3a996a        redis               "docker-entrypoint..."   22 hours ago        Up 22 hours                0.0.0.0:6379->6379/tcp   redis
[root@localhost ~]#

查看日志

[root@localhost ~]#  docker logs --tail 0 -f 8fdadbd21cf44f6f68f7ea4cae039550de8d3f7577b42c60e57401cb8b4d1931
usermod: no changes
Jul  9 09:52:16 syslogd started: BusyBox v1.31.1
Jul  9 09:52:16 sshd[32]: Server listening on :: port 22.
Jul  9 09:52:16 sshd[32]: Server listening on 0.0.0.0 port 22.
2021/07/09 09:52:16 [ WARN] Custom config "/data/gogs/conf/app.ini" not found. Ignore this warning if you're running for the first time
2021/07/09 09:52:16 [TRACE] Log mode: Console (Trace)
2021/07/09 09:52:16 [ INFO] Gogs 0.13.0+dev
2021/07/09 09:52:16 [TRACE] Work directory: /app/gogs
2021/07/09 09:52:16 [TRACE] Custom path: /data/gogs
2021/07/09 09:52:16 [TRACE] Custom config: /data/gogs/conf/app.ini
2021/07/09 09:52:16 [TRACE] Log path: /app/gogs/log
2021/07/09 09:52:16 [TRACE] Build time: 2021-05-19 07:16:50 UTC
2021/07/09 09:52:16 [TRACE] Build commit: ba8be9489e6d959fa9005fc7d38bf62562580d23
2021/07/09 09:52:16 [ INFO] Run mode: Development
2021/07/09 09:52:16 [ INFO] Listen on http://0.0.0.0:3000

创建Mysql用户
create database if not exists gogs default charset utf8 collate utf8_general_ci;
CREATE USER 'gogs'@'%' IDENTIFIED BY 'passwd';

# 登录授权
[root@itdev9903 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 200
Server version: 5.7.30 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show grants for 'gogs'@'%';
+----------------------------------+
| Grants for gogs@%                |
+----------------------------------+
| GRANT USAGE ON *.* TO 'gogs'@'%' |
+----------------------------------+
1 row in set (0.00 sec)

mysql> grant insert,select,update,delete,create,drop,alter,index on gogs.* to 'gogs'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql>FLUSH PRIVILEGES;

回收所有权限

revoke all privileges on gogs.* from 'gogs'@'%';
show grants for 'gogs'@'%';

附录:

1. git 常用命令

# 配置
git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com

# 查看
git --version
git status  

# 初始仓库
git init

# 添加至暂存区
git add ./file (将需要提交的提交到暂存区)

# 提交本地仓库
git commit - m 'feat: 注释' (提交到本地)
git commit --amend

# 快捷提交
git commit -am 'feat: 注释'

# 直接回退
git log --oneline
git checkout filename

# 从暂存区回退
git reset HEAD filename
git checkout -- filename

# 从本地仓回退
git log --oneline
git reset --hard XXX

# 从本地仓重置回退
git reflog
git reset --hard XXX

# 查看分支
git branch 查看本地所有分支
git branch -a 查看所有的分支
git branch -r 查看远程所有分支

# 创建分支
git branch 分支名称

# 切换分支
git checkout 分支名称

# 创建并切换
git checkout -b 分支名称

# 合并分支
git merge 目标分支 -m "描述"
git rebase 目标分支

# 将本地的Test分支推送到远端的master分支
git push origin Test:master

# 删除分支
git branch -d 分支
# 删除远程分支
git push origin --delete 分支 

# 查看tag
git tag

# 查看详情
git show tag名称

# 创建tag
git tag -a "v1.0" -m "描述"
git tag -a "v1.0" 标识码 -m "描述"

# 删除tag
git tag -d 标签名

# 查看远程仓库
git remote [-v]

# 删除关联
git remote remove origin

# 推送tag
git push origin --tags
git push tag名称

# 删除远程tag
git push origin --delete tag名称
 
# 获取远程tag
git fetch origin tag V1.2

# 拉取远程代码
git pull <远程主机名> <远程分支名>:<本地分支名>

# 一、开发分支(develop)上的代码达到上线的标准后,要合并到 master 分支
git checkout develop
git pull
git checkout master
git merge develop
git push -u origin master

# 二、当master代码改动了,需要更新开发分支(develop)上的代码
git checkout master 
git pull 
git checkout develop
git merge master 
git push -u origin develop

更多参考请查阅:常用 Git 命令清单 - 阮一峰的网络日志 (ruanyifeng.com)

2 git 提交规范

注释前缀 含义 样例
feat 新功能(feature) git commit -m "feat:导入主干"
fix 修补 bug git commit -m "fix: 修复bug"
docs 文档(documentation) git commit -m "docs:添加文档"
style 格式(不影响代码运行的变动) git commit -m "style:添加样式"
refactor 重构(即不是新增功能,也不是修改 bug 的代码变动) git commit -m "refactor:重构代码"
test 增加测试 git commit -m "test:添加测试代码"
chore 构建过程或辅助工具的变动 git commit -m "chore:修改构建顺序"

3. Git-SVN

yum -y install git-svn

# 下载一个 SVN 项目和它的整个代码历史,并初始化为 Git 代码库
$ git svn clone -s [repository]
# 查看当前版本库情况
$ git svn info
# 取回远程仓库所有分支的变化
$ git svn fetch
# 取回远程仓库当前分支的变化,并与本地分支变基合并
$ git svn rebase 
# 上传当前分支的本地仓库到远程仓库
$ git svn dcommit
# 拉取新分支,并提交到远程仓库
$ svn copy [remote_branch] [new_remote_branch] -m [message]
# 创建远程分支对应的本地分支
$ git checkout -b [local_branch] [remote_branch]

4. Git/SVN并存

git svn int http://ip/svn/demo/trunk  demo
git svn fetch -r HEAD12
cd demo
git remote add git  http://ip/path/demo.git12
git fetch git master    #获取git仓库的master分支
git fetch git 1.0       #获取git仓库的1.0分支
git fetch git           #获取所有git分支123
➜  demo git:(master) git branch -a
* master              #默认对应svn
remotes/git-svn     #svn分支
remotes/git/1.0     #远程git的1.0分支
remotes/git/master  #远程git的master分支12345
git merge  git-master1
# 从SVN同步
git svn rebase

# 提交SVN仓库
git svn dcommit

# 提交Git仓库
git push -u origin master

Git Contribution submission specification

常用全局配置

# 全局提交用户名与邮箱
git config --global user.name "username"
git config --global user.email "邮箱名@gmail.com"

# gitk乱码处理
git config --global gui.encoding utf-8
下载项目:git clone <仓库地址>如果要下载非master的某分支代码:git clone -b <分支名> <仓库地址>查看当前你所在分支:git branch (查看你当前的分支,*标识的就是你当前的分支)
创建和切换分支:git chaeckout -b <你的feature分支名称>
添加修改到缓冲区:git add .
检查项目状态:git status
描述并提交修改内容描述:git commit -m "<提交的内容描述>"
把项目提交到远程仓库:git push origin <你的feature分支名称>

如果你是管理员权限还需要这么做:

合并分支到master分支:git merge <feature分支>
删除分支:git branch -d <feature分支>
上一篇 下一篇

猜你喜欢

热点阅读