Compare commits
4 Commits
510e60a42e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6fecf6fc11 | |||
| 7abdf4b03c | |||
| 53f5a6952b | |||
| b84634a606 |
6
Dockerfile.ssh
Normal file
6
Dockerfile.ssh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
FROM alpine:3.19
|
||||||
|
COPY --chmod=555 entrypoint-ssh.sh /bin/entrypoint.sh
|
||||||
|
COPY --chmod=600 ssh_config /root/.ssh/config
|
||||||
|
RUN apk add --no-cache git openssh zsh
|
||||||
|
|
||||||
|
ENTRYPOINT ["zsh", "/bin/entrypoint.sh"]
|
||||||
35
README.md
Normal file
35
README.md
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# woodpecker-ssg-deploy
|
||||||
|
|
||||||
|
A Woodpecker plugin to push outputs created by SSGs into git repositories.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
deploy:
|
||||||
|
image: git.polynom.me/papatutuwawa/woodpecker-ssg-deploy:latest
|
||||||
|
# The push token
|
||||||
|
# NOTE: For gitea, this is currently an access token with Read/Write access
|
||||||
|
# to repositories.
|
||||||
|
secrets: [ token ]
|
||||||
|
settings:
|
||||||
|
# The EMail to use for the git user that does the pushing
|
||||||
|
email: "system@example.org"
|
||||||
|
# The name to use for the git user that does the pushing
|
||||||
|
name: "example.org CI System"
|
||||||
|
# The name of the environment variable that contains the push token
|
||||||
|
token_env: "TOKEN"
|
||||||
|
# The name of the directory containing the SSG output
|
||||||
|
output: "public"
|
||||||
|
# The name of the branch to push into. Defaults to "pages"
|
||||||
|
branch: "pages"
|
||||||
|
```
|
||||||
|
|
||||||
|
What the plugin does is initialize a new Git repository in the output directory,
|
||||||
|
add all files in the output directory to the repository and then force push to the original
|
||||||
|
repository on the specified branch.
|
||||||
|
|
||||||
|
For a real-life example [see here](https://git.polynom.me/PapaTutuWawa/blog.polynom.me).
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
See `LICENSE`.
|
||||||
48
entrypoint-ssh.sh
Normal file
48
entrypoint-ssh.sh
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/zsh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
branch=${PLUGIN_BRANCH:-"pages"}
|
||||||
|
token_env=${PLUGIN_TOKEN_ENV}
|
||||||
|
output=${PLUGIN_OUTPUT}
|
||||||
|
name=${PLUGIN_NAME}
|
||||||
|
email=${PLUGIN_EMAIL}
|
||||||
|
|
||||||
|
# Allow passing a different push SSH URL
|
||||||
|
clone_url=$CI_REPO_CLONE_SSH_URL
|
||||||
|
if [[ -n "$PLUGIN_SSH_URL" ]]; then
|
||||||
|
clone_url=${PLUGIN_SSH_URL}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$token_env" || -z "$branch" || -z "$name" || -z "$email" || -z "$clone_url" ]]; then
|
||||||
|
echo "Invalid configuration: Token environment variable name, branch name empty, name, clone URL, or email"
|
||||||
|
echo "Token env: $token_env"
|
||||||
|
echo "branch: $branch"
|
||||||
|
echo "Name: $name"
|
||||||
|
echo "Email: $email"
|
||||||
|
echo "Clone URL: $clone_url"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Setup the SSH directory
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
chown root:root ~/.ssh
|
||||||
|
chmod 700 ~/.ssh
|
||||||
|
|
||||||
|
# Setup the SSH key
|
||||||
|
print -rl -- ${(P)token_env} > ~/.ssh/id_rsa
|
||||||
|
chown root:root ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
|
||||||
|
# Setup git
|
||||||
|
git config --global user.email "$email"
|
||||||
|
git config --global user.name "$name"
|
||||||
|
git config --global --add safe.directory "$CI_WORKSPACE/$CI_REPO_OWNER/$CI_REPO_NAME/$output"
|
||||||
|
|
||||||
|
# Init a new repository in the output directory and add all files
|
||||||
|
git init -b "$branch" "$output"
|
||||||
|
cd "$output"
|
||||||
|
git add --all
|
||||||
|
git commit -m "Deploy new version $CI_COMMIT_SHA"
|
||||||
|
|
||||||
|
# Push the repository
|
||||||
|
git push -u "$clone_url" -f "$branch"
|
||||||
@@ -2,8 +2,10 @@
|
|||||||
branch=${PLUGIN_BRANCH:-"pages"}
|
branch=${PLUGIN_BRANCH:-"pages"}
|
||||||
token_env=${PLUGIN_TOKEN_ENV}
|
token_env=${PLUGIN_TOKEN_ENV}
|
||||||
output=${PLUGIN_OUTPUT}
|
output=${PLUGIN_OUTPUT}
|
||||||
if [[ -z "$token_env" ]] || [[ -z "$branch" ]]; then
|
name=${PLUGIN_NAME}
|
||||||
echo "Invalid configuration: Token environment variable name or branch name empty"
|
email=${PLUGIN_EMAIL}
|
||||||
|
if [[ -z "$token_env" ]] || [[ -z "$branch" ]] || [[ -z "$name"]] || [[ -z "$email" ]]; then
|
||||||
|
echo "Invalid configuration: Token environment variable name, branch name empty, name, or email"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -13,8 +15,8 @@ if [[ "$?" -ne "0" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -n "$PLUGIN_EMAIL" ]] && git config --config user.email "$PLUGIN_EMAIL"
|
git config --global user.email "$email"
|
||||||
[[ -n "$PLUGIN_NAME" ]] && git config --config user.name "$PLUGIN_NAME"
|
git config --global user.name "$name"
|
||||||
git config --global --add safe.directory "$CI_WORKSPACE/$CI_REPO_OWNER/$CI_REPO_NAME/$output"
|
git config --global --add safe.directory "$CI_WORKSPACE/$CI_REPO_OWNER/$CI_REPO_NAME/$output"
|
||||||
|
|
||||||
# Init a new repository in the output directory and add all files
|
# Init a new repository in the output directory and add all files
|
||||||
|
|||||||
3
ssh_config
Normal file
3
ssh_config
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Host *
|
||||||
|
StrictHostKeyChecking no
|
||||||
|
UserKnownHostsFile=/dev/null
|
||||||
Reference in New Issue
Block a user