Adding sample folder for use with the README.md.
This commit is contained in:
parent
1b80f27d64
commit
5535fdd164
|
@ -0,0 +1,62 @@
|
|||
# syntax=docker/dockerfile:1.4
|
||||
FROM golang:1.20-alpine AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN <<EOF
|
||||
apk --update add --no-cache git bash make alpine-sdk g++
|
||||
git clone https://git.iratusmachina.com/iratusmachina/gocustomurls.git gurls
|
||||
cd gurls
|
||||
make build
|
||||
EOF
|
||||
|
||||
FROM alpine AS run
|
||||
|
||||
ARG USERNAME
|
||||
ARG UID
|
||||
ARG GID
|
||||
ARG PORT
|
||||
|
||||
RUN <<EOF
|
||||
addgroup --gid ${GID} ${USERNAME}
|
||||
adduser --uid ${UID} --ingroup ${USERNAME} --gecos "" --disabled-password --home "/home/$USERNAME" $USERNAME
|
||||
chmod -R 755 /home/$USERNAME
|
||||
chown -R ${UID}:${GID} /home/$USERNAME
|
||||
EOF
|
||||
|
||||
COPY --from=build /app/gurls/artifacts/gocustomurls /home/$USERNAME/gocustomurls
|
||||
|
||||
RUN <<EOF
|
||||
mkdir -p /var/lib/apptemp
|
||||
cp /home/$USERNAME/gocustomurls /var/lib/apptemp/gocustomurls
|
||||
chown -R ${UID}:${GID} /home/$USERNAME
|
||||
chown -R ${UID}:${GID} /var/lib/apptemp
|
||||
ls -lah /home/$USERNAME
|
||||
EOF
|
||||
|
||||
|
||||
ENV HOME=/home/$USERNAME
|
||||
|
||||
COPY <<EOF start.sh
|
||||
#!/usr/bin/env sh
|
||||
printenv
|
||||
cd "${HOME}"
|
||||
ls -lah .
|
||||
if [ ! -f "${HOME}/gocustomurls" ]
|
||||
then
|
||||
cp /var/lib/apptemp/gocustomurls ${HOME}/gocustomurls
|
||||
rm /var/lib/apptemp/gocustomurls
|
||||
fi
|
||||
${HOME}/gocustomurls -conf ${HOME}/config.json
|
||||
EOF
|
||||
|
||||
RUN <<EOF
|
||||
chown ${UID}:${GID} start.sh
|
||||
chmod u+x start.sh
|
||||
EOF
|
||||
|
||||
EXPOSE $PORT
|
||||
|
||||
USER $USERNAME
|
||||
|
||||
CMD ["sh", "-c", "./start.sh" ]
|
20
README.md
20
README.md
|
@ -20,11 +20,23 @@ So I used golang for this project.
|
|||
```sh
|
||||
$ ./artifacts/gocustomurls --conf <PATH_TO_CONF_FILE>
|
||||
```
|
||||
A sample config file is located [here](./sample/config.json)
|
||||
A sample config file is located [here](./sample/config.json) and a sample rules file is located [here](./sample/rules.json)
|
||||
|
||||
## SystemD
|
||||
|
||||
A sample systemd file is located [here](./sample/gocustomurls.service)
|
||||
A sample systemd file is located [here](./sample/plain/gocustomurls.service). You should run this set of commands from [here](./sample/plain/commands.md)
|
||||
|
||||
|
||||
## Docker
|
||||
|
||||
A sample Dockefile for use with systemd is [here](./sample/withDocker/Dockerfile.1). You should run this set of commands from [here](./sample/withDocker/commands.md).
|
||||
|
||||
If you do not want to use systemd, you can run this instead:
|
||||
|
||||
```sh
|
||||
$ HOME=${PWD} docker build -t appimage/gocustomurls --build-arg UID=$(id -u) --build-arg GID=$(id -g) --build-arg USERNAME=$(whoami) --build-arg PORT=7070 --no-cache --progress=plain .
|
||||
$
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
|
@ -52,9 +64,9 @@ jbowen.dev/cereal (download)
|
|||
* [x] ~~Figure how to use logrotate (a linux utility)~~
|
||||
* [x] Figure how to do log rotation as part of this app's function
|
||||
* [x] Add tests
|
||||
* [ ] Add systemd.service and explanation
|
||||
* [x] Add systemd.service and explanation
|
||||
* [ ] Add Dockerfile and explanation
|
||||
* [ ] Figure how to use `goreleaser` [here](https://nfpm.goreleaser.com/) to release deb and rpm packages (so basically split it, goreleaser for github and woodpecker for Woodpecker)
|
||||
* [ ] Add mirror to Github
|
||||
* [ ] Add Github action
|
||||
* [ ] Figure how to use `goreleaser` [here](https://nfpm.goreleaser.com/) to release deb and rpm packages (so basically split it, goreleaser for github and woodpecker for Woodpecker)
|
||||
* [ ] Update README.md
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"rulesPath":"HOME/rules.json",
|
||||
"logPath":"HOME/app.log",
|
||||
"rulesPath":"/var/lib/$MYUSER/rules.json",
|
||||
"logPath":"/var/lib/$MYUSER/app.log",
|
||||
"compress":false,
|
||||
"sizeToRotate":"1kB",
|
||||
"port":"9999"
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
[Unit]
|
||||
Description=A custom url mapper for go packages!
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/opt/gocustomurls --conf $HOME/app.conf
|
||||
Restart=always
|
||||
SyslogIdentifier=gocustomurls
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -0,0 +1,37 @@
|
|||
# Set of commands
|
||||
|
||||
Also found [here](https://iratusmachina.com/#production-go-systemd-attempt-four)
|
||||
|
||||
```sh
|
||||
$ cp <BINARY> /usr/local/bin
|
||||
$ sudo mkdir -p /var/lib/<your user>
|
||||
$ sed -i 's/$MYUSER/<your user>/g' gocustomurls.service
|
||||
$ sed -i 's/$MYUSER/<your user>/g' config.json
|
||||
$ sudo cp gocustomurls.service /etc/systemd/system/
|
||||
$ sudo useradd --system --comment 'Go Custom Urls Service' --no-create-home <your user>
|
||||
useradd: failed to reset the lastlog entry of UID 992: No such file or directory
|
||||
$ sudo passwd -d <your user>
|
||||
passwd: password changed.
|
||||
$ getent passwd <your user>
|
||||
<your user>:x:992:991:Go Custom Urls Service:/home/<your user>:/bin/bash
|
||||
$ sudo cp config.json /var/lib/<your user>
|
||||
$ sudo cp rules.json /var/lib/<your user>
|
||||
$ sudo ls /var/lib/<your user>/
|
||||
config.json rules.json
|
||||
$ sudo chmod -R 770 /var/lib/<your user>
|
||||
$ sudo chown -R <your user>:<your user> /var/lib/<your user>
|
||||
$ sudo systemctl daemon-reload
|
||||
$ sudo systemctl start gocustomurls.service
|
||||
$ sudo systemctl status gocustomurls.service
|
||||
● gocustomurls.service - GocustomUrls. A custom url mapper for go packages!
|
||||
Loaded: loaded (/etc/systemd/system/gocustomurls.service; disabled; preset: disabled)
|
||||
Drop-In: /usr/lib/systemd/system/service.d
|
||||
└─10-timeout-abort.conf
|
||||
Active: active (running) since Sat 2024-07-20 06:52:09 UTC; 23s ago
|
||||
Main PID: 4020 (gocustomurls)
|
||||
Tasks: 6 (limit: 2319)
|
||||
Memory: 7.1M (peak: 7.5M)
|
||||
CPU: 14ms
|
||||
CGroup: /system.slice/gocustomurls.service
|
||||
└─4020 /usr/local/bin/gocustomurls -conf /var/lib/<your user>/config.json
|
||||
```
|
|
@ -0,0 +1,15 @@
|
|||
[Unit]
|
||||
Description=GocustomUrls. A custom url mapper for go packages!
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=/var/lib/$MYUSER
|
||||
Type=simple
|
||||
User=$MYUSER
|
||||
Group=$MYUSER
|
||||
ExecStart=/usr/local/bin/gocustomurls -conf /var/lib/$MYUSER/config.json
|
||||
SyslogIdentifier=gocustomurls
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"mappings": [
|
||||
{
|
||||
"vanity_url":"scale.dev/x/migrate",
|
||||
"protocol":"git",
|
||||
"real_url":"https://codeberg.org/Gusted/mCaptcha.git"
|
||||
},
|
||||
{
|
||||
"vanity_url":"localhost:7070/x/touche",
|
||||
"protocol":"git",
|
||||
"real_url":"https://github.com/dariubs/GoBooks.git"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
# syntax=docker/dockerfile:1.4
|
||||
FROM golang:1.20-alpine AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN <<EOF
|
||||
apk --update add --no-cache git bash make alpine-sdk g++
|
||||
git clone https://git.iratusmachina.com/iratusmachina/gocustomurls.git gurls
|
||||
cd gurls
|
||||
make build
|
||||
EOF
|
||||
|
||||
FROM alpine AS run
|
||||
|
||||
ARG USERNAME
|
||||
ARG UID
|
||||
ARG GID
|
||||
ARG PORT
|
||||
|
||||
RUN <<EOF
|
||||
addgroup --gid ${GID} ${USERNAME}
|
||||
adduser --uid ${UID} --ingroup ${USERNAME} --gecos "" --disabled-password --home "/home/$USERNAME" $USERNAME
|
||||
chmod -R 755 /home/$USERNAME
|
||||
chown -R ${UID}:${GID} /home/$USERNAME
|
||||
EOF
|
||||
|
||||
COPY --from=build /app/gurls/artifacts/gocustomurls /home/$USERNAME/gocustomurls
|
||||
|
||||
RUN <<EOF
|
||||
mkdir -p /var/lib/apptemp
|
||||
cp /home/$USERNAME/gocustomurls /var/lib/apptemp/gocustomurls
|
||||
chown -R ${UID}:${GID} /home/$USERNAME
|
||||
chown -R ${UID}:${GID} /var/lib/apptemp
|
||||
ls -lah /home/$USERNAME
|
||||
EOF
|
||||
|
||||
|
||||
ENV HOME=/home/$USERNAME
|
||||
|
||||
COPY <<EOF start.sh
|
||||
#!/usr/bin/env sh
|
||||
printenv
|
||||
cd "${HOME}"
|
||||
ls -lah .
|
||||
if [ ! -f "${HOME}/gocustomurls" ]
|
||||
then
|
||||
cp /var/lib/apptemp/gocustomurls ${HOME}/gocustomurls
|
||||
rm /var/lib/apptemp/gocustomurls
|
||||
fi
|
||||
${HOME}/gocustomurls -conf ${HOME}/config.json
|
||||
EOF
|
||||
|
||||
RUN <<EOF
|
||||
chown ${UID}:${GID} start.sh
|
||||
chmod u+x start.sh
|
||||
EOF
|
||||
|
||||
EXPOSE $PORT
|
||||
|
||||
USER $USERNAME
|
||||
|
||||
CMD ["sh", "-c", "./start.sh" ]
|
|
@ -0,0 +1,44 @@
|
|||
# Set of commands
|
||||
|
||||
Also found [here](https://iratusmachina.com/#production-go-systemd-attempt-five)
|
||||
|
||||
```sh
|
||||
$ sudo useradd --system --comment 'Go Custom Urls Service' --no-create-home <your user>
|
||||
useradd: failed to reset the lastlog entry of UID 992: No such file or directory
|
||||
$ sudo passwd -d <your user>
|
||||
passwd: password changed.
|
||||
$ getent passwd <your user>
|
||||
<your user>:x:992:991:Go Custom Urls Service:/home/<your user>:/bin/bash
|
||||
$ sudo mkdir -p /var/lib/<your user>/appfiles/otherfiles
|
||||
$ sudo cp docker-compose.yml /var/lib/<your user>/appfiles/
|
||||
$ sudo cp Dockerfile.1 /var/lib/<your user>/appfiles/Dockerfile
|
||||
$ sed -i 's/$MYUSER/<your user>/g' gocustomurls.service
|
||||
$ sed -i 's/$MYUSER/<your user>/g' config.json
|
||||
$ sudo cp config.json /var/lib/<your user>/appfiles/othefiles
|
||||
$ sudo cp rules.json /var/lib/<your user>/appfiles/otherfiles
|
||||
$ sudo chmod -R 770 /var/lib/<your user>
|
||||
$ sudo chown -R <your user>:<your user> /var/lib/<your user>
|
||||
$ sudo cp gocustomurls.service /etc/systemd/system/
|
||||
$ sudo systemctl daemon-reload
|
||||
$ sudo systemctl start gocustomurls.service
|
||||
● gocustomurls.service - GocustomUrls. A custom url mapper for go packages!
|
||||
Loaded: loaded (/etc/systemd/system/gocustomurls.service; disabled; preset: disabled)
|
||||
Drop-In: /usr/lib/systemd/system/service.d
|
||||
└─10-timeout-abort.conf
|
||||
Active: active (exited) since Sat 2024-08-03 18:08:46 UTC; 50s ago
|
||||
Process: 24117 ExecStart=/bin/bash -c HOME=/var/lib/<your user> USER_ID=$(id -u) GROUP_ID=$(id -g) USERNAME=$(whoami) docker compose --file /var/lib/<your user>/docker-compose.yml up --detach --force-recreate (code=exited, status=0/SUCCESS)
|
||||
Main PID: 24117 (code=exited, status=0/SUCCESS)
|
||||
CPU: 125ms
|
||||
|
||||
Aug 03 18:08:45 fedoramachine gocustomurls[24132]: #17 DONE 0.0s
|
||||
Aug 03 18:08:45 fedoramachine gocustomurls[24132]: #18 [app] resolving provenance for metadata file
|
||||
Aug 03 18:08:45 fedoramachine gocustomurls[24132]: #18 DONE 0.0s
|
||||
Aug 03 18:08:45 fedoramachine gocustomurls[24132]: Network <your user>_default Creating
|
||||
Aug 03 18:08:45 fedoramachine gocustomurls[24132]: Network <your user>_default Created
|
||||
Aug 03 18:08:45 fedoramachine gocustomurls[24132]: Container gocustomurls_app Creating
|
||||
Aug 03 18:08:45 fedoramachine gocustomurls[24132]: Container gocustomurls_app Created
|
||||
Aug 03 18:08:45 fedoramachine gocustomurls[24132]: Container gocustomurls_app Starting
|
||||
Aug 03 18:08:46 fedoramachine gocustomurls[24132]: Container gocustomurls_app Started
|
||||
Aug 03 18:08:46 fedoramachine systemd[1]: Finished gocustomurls.service - GocustomUrls. A custom url mapper for go packages!.
|
||||
|
||||
```
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
- USERNAME=${USERNAME}
|
||||
- UID=${USER_ID}
|
||||
- GID=${GROUP_ID}
|
||||
- PORT=${PORT:-7070}
|
||||
labels:
|
||||
- "maintainer=iratusmachina"
|
||||
image: appimage/gocustomurls
|
||||
logging:
|
||||
driver: journald
|
||||
container_name: gocustomurls_app
|
||||
ports:
|
||||
- "7070:7070"
|
||||
volumes:
|
||||
- ${PWD}/otherfiles:/home/${USERNAME}
|
|
@ -0,0 +1,18 @@
|
|||
[Unit]
|
||||
Description=GocustomUrls. A custom url mapper for go packages!
|
||||
After=docker.service
|
||||
PartOf=docker.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
WorkingDirectory=/var/lib/$MYUSER
|
||||
User=$MYUSER
|
||||
Group=$MYUSER
|
||||
ExecStart=/bin/bash -c "HOME=/var/lib/$MYUSER USER_ID=$(id -u) GROUP_ID=$(id -g) USERNAME=$(whoami) docker compose --file /var/lib/$MYUSER/docker-compose.yml up --detach --force-recreate"
|
||||
ExecStop=/bin/bash -c "HOME=/var/lib/$MYUSER USER_ID=$(id -u) GROUP_ID=$(id -g) USERNAME=$(whoami) docker compose --file /var/lib/$MYUSER/docker-compose.yml down -v"
|
||||
SyslogIdentifier=gocustomurls
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in New Issue