Boom
This commit is contained in:
parent
32de723e6a
commit
67943d3fed
3 changed files with 126 additions and 27 deletions
|
@ -9,17 +9,20 @@ title: Mirroring Gitea to Other Repository Management Services (GitHub, GitLab,
|
|||
draft: false
|
||||
---
|
||||
|
||||
**NOTE**: Gitea now supports this out-of-the-box and probably fits your
|
||||
use-case: https://docs.gitea.io/en-us/repo-mirror/
|
||||
|
||||
I have a [Gitea][gitea] instance I self-host at home. I keep most of my
|
||||
repositories there, but I recognize that most other developers and potential
|
||||
employers will want to see [my work *on* GitHub][me-on-github].
|
||||
employers will want to see [my work _on_ GitHub][me-on-github].
|
||||
|
||||
<!--more-->
|
||||
|
||||
# TL;DR
|
||||
|
||||
+ Setup an SSH key for your Gitea instance on the relevant external repositories
|
||||
+ Leverage `post-receive` git hooks in Gitea to push changes to the relevant
|
||||
external repositories while identifying with your new SSH key
|
||||
- Setup an SSH key for your Gitea instance on the relevant external repositories
|
||||
- Leverage `post-receive` git hooks in Gitea to push changes to the relevant
|
||||
external repositories while identifying with your new SSH key
|
||||
|
||||
Also, most of the magic is [here](#post-receive-script).
|
||||
|
||||
|
@ -43,16 +46,16 @@ Gitea supports a few [git hooks][1], which are a simple way to run a script when
|
|||
something happens. As far as a repository manager is concerned, the only real
|
||||
hooks that matter are the following (which Gitea supports):
|
||||
|
||||
+ `pre-receive`: Runs when a client pushes code to the repository. You can use
|
||||
this to prevent, for example, code that fails linters, doesn't pass tests,
|
||||
or even that can't be merged using a specific merge strategy.
|
||||
+ `update`: Runs for each branch being updated when a client pushes code to the
|
||||
repository. This is similar to pre-receive, but allows for more fine-grained
|
||||
control. Maybe you want to only make the previous restrictions on your
|
||||
`master` branch. This would be the way to do it.
|
||||
+ `post-receive`: Runs after your `pre-receive` and `update` hooks have finished
|
||||
when a client pushes code to the repository. This is what we'll be
|
||||
leveraging to push code downstream!
|
||||
- `pre-receive`: Runs when a client pushes code to the repository. You can use
|
||||
this to prevent, for example, code that fails linters, doesn't pass tests,
|
||||
or even that can't be merged using a specific merge strategy.
|
||||
- `update`: Runs for each branch being updated when a client pushes code to the
|
||||
repository. This is similar to pre-receive, but allows for more fine-grained
|
||||
control. Maybe you want to only make the previous restrictions on your
|
||||
`master` branch. This would be the way to do it.
|
||||
- `post-receive`: Runs after your `pre-receive` and `update` hooks have finished
|
||||
when a client pushes code to the repository. This is what we'll be
|
||||
leveraging to push code downstream!
|
||||
|
||||
With that lengthy introduction, let's dive in!
|
||||
|
||||
|
@ -62,17 +65,17 @@ Alrighty, this has a few simple steps, so let's outline what we need to do
|
|||
first:
|
||||
|
||||
1. Setup SSH keys for Gitea and your other repository management services
|
||||
1. Generate fresh keys (`ssh-keygen -f gitea` will generate a private key in
|
||||
the `gitea` file and a public key in the `gitea.pub` file)
|
||||
2. Add the public key (`gitea.pub`) to your "mirrors-to-be" repositories *with
|
||||
write access*
|
||||
+ **Note**: I recommend at the very least to create one Gitea key and add it
|
||||
to the individual repositories, though individual keys for each repository
|
||||
is tighter security in case your Gitea instance becomes compromised
|
||||
+ **Note**: Your "mirrors-to-be" repositories must be blank or have related
|
||||
histories!
|
||||
1. Generate fresh keys (`ssh-keygen -f gitea` will generate a private key in
|
||||
the `gitea` file and a public key in the `gitea.pub` file)
|
||||
2. Add the public key (`gitea.pub`) to your "mirrors-to-be" repositories _with
|
||||
write access_
|
||||
- **Note**: I recommend at the very least to create one Gitea key and add it
|
||||
to the individual repositories, though individual keys for each repository
|
||||
is tighter security in case your Gitea instance becomes compromised
|
||||
- **Note**: Your "mirrors-to-be" repositories must be blank or have related
|
||||
histories!
|
||||
2. Setup the `post-receive` hook on your Gitea repository to push using the
|
||||
newly generated private key to the mirror(s)
|
||||
newly generated private key to the mirror(s)
|
||||
|
||||
I'm not going to explain much on how to add Deploy Keys for the various
|
||||
repository management systems out there, so here's a link [explaining the process
|
||||
|
@ -84,9 +87,8 @@ Now we're all set for the magic! Also, for reference and sanity, I'm running
|
|||
Gitea in Docker on an Arch Linux server with the following version (but this
|
||||
should work pretty much regardless):
|
||||
|
||||
+ Gitea Version: `3b612ce built with go1.11.5 : bindata, sqlite,
|
||||
sqlite_unlock_notify`
|
||||
+ Git Version: `2.18.1`
|
||||
- Gitea Version: `3b612ce built with go1.11.5 : bindata, sqlite, sqlite_unlock_notify`
|
||||
- Git Version: `2.18.1`
|
||||
|
||||
Let's go ahead and open up our Gitea repository's index page.
|
||||
|
||||
|
|
96
content/ourcraft-status.md
Normal file
96
content/ourcraft-status.md
Normal file
|
@ -0,0 +1,96 @@
|
|||
---
|
||||
title: Ourcraft Server Status Checker
|
||||
---
|
||||
|
||||
<p id="server-status-loading">
|
||||
Checking <code>ourcraft.lyte.dev</code> server status...
|
||||
</p>
|
||||
|
||||
<div id="server-status-check-failed">
|
||||
<p>
|
||||
Failed to retrieve <code>ourcraft.lyte.dev</code> server status. Unfortunately, that usually means we're <code><span style="color: var(--syntax-mag);">OFFLINE</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
Please yell at <code>@lytedev</code> in the Ourcraft Discord to fix it!
|
||||
</p>
|
||||
<p><button id="server-status-check-button">Try Again</button></p>
|
||||
</div>
|
||||
|
||||
<div id="server-status-online" style="display: none;">
|
||||
<p>Server <code>ourcraft.lyte.dev</code> is <code><span style="color: var(--syntax-name);">ONLINE</span></code></p>
|
||||
<p id="server-status-player-info" style="display: none;">There are currently <span id="server-status-current-num-players">0</span>/<span id="server-status-max-players">20</span> players online.</p>
|
||||
<h3 id="server-status-player-sampling-header" style="display: none;">Online Players</h3>
|
||||
<ul id="server-status-player-sampling" style="display: none;">
|
||||
<li>Player</li>
|
||||
</ul>
|
||||
<p id="server-status-player-sampling-insufficient" style="display: none">... and more!</p>
|
||||
</div>
|
||||
|
||||
<p id="server-status-offline" style="display: none;">
|
||||
Server is <code><span style="color: var(--syntax-mag);">OFFLINE</span></code>
|
||||
</p>
|
||||
|
||||
<script src="https://mcapi.us/scripts/minecraft.min.js"></script>
|
||||
<script>
|
||||
function showServerStatus(key) {
|
||||
for (const name of ['server-status-check-failed', 'server-status-online', 'server-status-offline', 'server-status-loading']) {
|
||||
if (name == key) {
|
||||
document.getElementById(name).style.display = 'block'
|
||||
} else {
|
||||
document.getElementById(name).style.display = 'none'
|
||||
}
|
||||
}
|
||||
}
|
||||
function checkServerStatus() {
|
||||
showServerStatus('server-status-loading')
|
||||
MinecraftAPI.getServerStatus('ourcraft.lyte.dev', {port: 25565}, function (err, status) {
|
||||
console.debug("Status Errors:", err || false)
|
||||
if (err || !('online' in status)) {
|
||||
showServerStatus('server-status-check-failed')
|
||||
} else {
|
||||
handleOnlineStatus(status)
|
||||
}
|
||||
});
|
||||
}
|
||||
function handleOnlineStatus(status) {
|
||||
console.debug("Status Data:", status)
|
||||
if (status.online === true) {
|
||||
showServerStatus('server-status-online')
|
||||
const info = document.getElementById('server-status-player-info')
|
||||
const samplingHeader = document.getElementById('server-status-player-sampling-header')
|
||||
const samplingList = document.getElementById('server-status-player-sampling')
|
||||
const insufficient = document.getElementById('server-status-player-sampling-insufficient')
|
||||
|
||||
info.style.display = 'none'
|
||||
samplingHeader.style.display = 'none'
|
||||
samplingList.style.display = 'none'
|
||||
insufficient.style.display = 'none'
|
||||
|
||||
if ('players' in status) {
|
||||
if ('max' in status.players && 'now' in status.players) {
|
||||
info.style.display = 'block'
|
||||
document.getElementById('server-status-current-num-players').textContent = status.players.now
|
||||
document.getElementById('server-status-max-players').textContent = status.players.max
|
||||
}
|
||||
if ('sample' in status.players) {
|
||||
samplingHeader.style.display = 'block'
|
||||
samplingList.style.display = 'block'
|
||||
samplingList.textContent = ''
|
||||
for (const player of status.players.sample) {
|
||||
const newListItem = document.createElement('li')
|
||||
newListItem.textContent = player.name
|
||||
newListItem.title = player.id
|
||||
samplingList.appendChild(newListItem)
|
||||
}
|
||||
if (status.players.sample.length != status.players.now) {
|
||||
document.getElementById('server-status-player-sampling-insufficient').style.display = 'block'
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
showServerStatus('server-status-offline')
|
||||
}
|
||||
}
|
||||
document.getElementById("server-status-check-button").addEventListener("click", checkServerStatus)
|
||||
checkServerStatus()
|
||||
</script>
|
|
@ -1,3 +1,4 @@
|
|||
main > .highlight .chroma-highlight,
|
||||
main > .highlight pre.chroma
|
||||
border 0
|
||||
padding 0.25em 0.5em
|
||||
|
|
Loading…
Reference in a new issue