update from sparkleup
This commit is contained in:
parent
41df1c6407
commit
28b59ad34f
|
@ -47,6 +47,7 @@ nano index.html
|
|||
Within that file, add a snippet of HTML that you will recognize:
|
||||
|
||||
```html
|
||||
[label index.html]
|
||||
<html>
|
||||
<head>
|
||||
<title>Testing Gitea</title>
|
||||
|
@ -92,6 +93,7 @@ sudo nano /etc/nginx/sites-available/static-sammy
|
|||
In this file, enter the following:
|
||||
|
||||
```nginx
|
||||
[label /etc/nginx/sites-available/static-sammy]
|
||||
server {
|
||||
server_name static-sammy.com;
|
||||
listen 80;
|
||||
|
@ -129,6 +131,7 @@ sudo nginx -t
|
|||
If all has gone well, you should see something like the following:
|
||||
|
||||
```
|
||||
[secondary_label Output]
|
||||
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
|
||||
nginx: configuration file /etc/nginx/nginx.conf test is successful
|
||||
```
|
||||
|
@ -178,6 +181,8 @@ It's important to remember to add that `.` at the end of the `git clone` command
|
|||
|
||||
Now that Nginx is serving the site from our checked out repository, we can set up the `post-receive` hook to update the site.
|
||||
|
||||
### Creating the Hook Script
|
||||
|
||||
Git hooks for Gitea live in the repository that Gitea serves from. These are located in the data directory, predictably within the `repositories` subdirectory. Move to your data directory using `cd`, then move to your repository's `hooks` directory:
|
||||
|
||||
```command
|
||||
|
@ -187,6 +192,7 @@ cd git/repositories/sammy/static-sammy.com.git/hooks
|
|||
If you list the files in this directory, you will see a whole host of sample scripts, plus a few directories:
|
||||
|
||||
```
|
||||
[secondary_label Output]
|
||||
total 92
|
||||
drwxr-xr-x 6 git git 4096 Jun 27 17:29 ./
|
||||
drwxr-xr-x 7 git git 4096 Jun 27 17:43 ../
|
||||
|
@ -223,18 +229,19 @@ nano post-receive.d/deploy
|
|||
This file can be any executable script. In our case, since we'll just be running a simple `git` command, we'll use a Bash script. Enter the following into that file:
|
||||
|
||||
```bash
|
||||
[label post-receive.d/deploy]
|
||||
#!/bin/bash
|
||||
|
||||
set -eux
|
||||
|
||||
git --work-tree=/var/www/static-sammy.com/ --git-dir=/var/www/static-sammy.com/.git pull
|
||||
git --git-dir=/var/www/static-sammy.com/.git --work-tree=/var/www/static-sammy.com/ pull --ff-only
|
||||
```
|
||||
|
||||
Let's break this script down into its parts to understand what's happening:
|
||||
|
||||
* `#!/bin/bash` tells the shell to use the bash command to run the script.
|
||||
* `set -eux` specifies three options: `e` means that the script will exit on a failure, `u` means that unset variables will be an error, and `x` means that it will print the commands as it executes them. These options are good practice for preventing scripts from continuing to execute when there are errors.
|
||||
* The `git` command breaks down into `git pull` which pulls new changes from the repository, while the `--work-tree` and `--git-dir` options tell Git to use the `.git` directory within the checked out branch for all of its configuration.
|
||||
* The `git` command breaks down into `git pull` which pulls new changes from the repository, while the `--work-tree` and `--git-dir` options tell Git to use the `.git` directory within the checked out branch for all of its configuration. `--ff-only` instructs `git pull` to use fast-forward reconciliation when pulling new commits.
|
||||
|
||||
Once you're done editing the script and have saved and closed it, use `chmod` to make the script executable:
|
||||
|
||||
|
@ -242,9 +249,38 @@ Once you're done editing the script and have saved and closed it, use `chmod` to
|
|||
chmod a+x post-receive.d/deploy
|
||||
```
|
||||
|
||||
### For Gitea Running in Docker
|
||||
|
||||
If Gitea is running in a Docker container --- if, for instance, you deployed it using the Docker Compose method in the tutorial linked above --- you will need to make a few changes to make the repository accessible from within the container. First, edit the `docker-compose.yml` file and move to the `volumes:` entry. Add a new line to that list:
|
||||
|
||||
```yaml
|
||||
[label docker-compose.yml]
|
||||
volumes:
|
||||
...
|
||||
<^>- /var/www/static-sammy.com:/var/www/static-sammy.com<^>
|
||||
```
|
||||
|
||||
This will mount that directory as a volume that the container can access. You will need to restart your Gitea containers:
|
||||
|
||||
```command
|
||||
docker-compose down
|
||||
docker-compose up
|
||||
```
|
||||
|
||||
Next, you will need to change the remote URL for the repository to the proper location for within the Docker container.
|
||||
|
||||
```command
|
||||
git remote set-url origin file:///data/git/repositories/sammy/static-sammy.com.git
|
||||
```
|
||||
|
||||
Here, we've changed the original URL we used to check out the branch from `/<^>path_to_gitea_installation<^>/repositories/sammy/static-sammy.com.git` to use `/data/git/` as the path to the installation, as that is how the volume is mapped in `docker-compose.yml`. As always, be sure to use the username and repository name appropriate to your project.
|
||||
|
||||
### Testing the `post-receive` Hook
|
||||
|
||||
Now, after Gitea receives a new commit and it's written to disk, it will run this script to update the branch checked out in `/var/www/static-sammy.com`. To test this out, change the `index.html` file on your local working directory to include a congratulations message. For example, change the file so that it resembles this:
|
||||
|
||||
```html
|
||||
[label index.html]
|
||||
<html>
|
||||
<head>
|
||||
<title>Testing Gitea</title>
|
||||
|
@ -268,4 +304,26 @@ And push your changes:
|
|||
git push origin main
|
||||
```
|
||||
|
||||
This time, you should see some additional output from Git. Because you set the `-x` option in our deploy script, you'll see the output of that script during the process, prefixed with `remote:`.
|
||||
|
||||
```
|
||||
[secondary_label Output]
|
||||
Enumerating objects: 5, done.
|
||||
Counting objects: 100% (5/5), done.
|
||||
Delta compression using up to 8 threads
|
||||
Compressing objects: 100% (2/2), done.
|
||||
Writing objects: 100% (3/3), 312 bytes | 312.00 KiB/s, done.
|
||||
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
|
||||
remote: + cd /var/www/static-sammy.com
|
||||
remote: + git --git-dir=/var/www/static-sammy.com/.git pull --ff-only
|
||||
remote: From file:///data/git/repositories/sammy/static-sammy.com
|
||||
remote: 28c52bf..95cde6f main -> origin/main
|
||||
remote: Updating 28c52bf..95cde6f
|
||||
remote: Fast-forward
|
||||
remote: . Processing 1 references
|
||||
remote: Processed 1 references in total
|
||||
To git.static-sammy.com:sammy/static-sammy.com.git
|
||||
8eed10f..95cde6f main -> main
|
||||
```
|
||||
|
||||
## Conclusion
|
||||
|
|
Loading…
Reference in New Issue