[Docs]: Examples for docker usage
Describe the documentation issue
The current documentation regarding the Docker section is missing how to use it. I want to try and run the docker image locally, but I am not being able to figure it out from checking the docker-compose.yml / Makefile, as it does not really show usages.
This was as far as I currently got:
$ docker run -it -v $(pwd):/app --workdir /app --env TARGET_GH_TOKEN=$(gh auth token) --env SOURCE_GH_TOKEN=$(gh auth token) --env SOURCE_REPO_PATH=<owner/template> --env UPSTREAM_BRANCH=main --env GITHUB_SERVER_URL=https://github.com --rm andyaugustin/actions-template-sync:v2.5.2
::group::git init
::info::set git global configuration
fatal: not in a git directory
$(pwd) in above docker command denotes the following host directory structure.
~/my/project/
├── .git
└── src
Not sure how/what I need to mount. Could you please elaborate?
Links
- https://andreasaugustin.github.io/actions-template-sync/DOCKER/
- #254
Acknowledgements
- [x] I may be able to submit a pull-request to fix this issue.
@AndreasAugustin Could you supply some examples here on how-to-use the docker image?
🦗
Is this repo still maintained?
Hi @ToshY repository is stil maintained but need to admit not super actively. This issue is most likely a duplicate of #254 Seems the docker image is not widely used but I will try to find some time to add some docs 👍
Hey @AndreasAugustin 👋
That would be much appreciated, as I want to try and use this as it seems to be a more robust solution than other "template sync" alternatives (like coopTilleuls/template-sync), so having a couple basic docker examples would be nice 👍
Hey @AndreasAugustin 👋
That would be much appreciated, as I want to try and use this as it seems to be a more robust solution than other "template sync" alternatives (like coopTilleuls/template-sync), so having a couple basic docker examples would be nice 👍
Nice. Can you possibly give some more details how you want to use it? Always interested in some use cases.
@ToshY I think it is actually a bug. To solve it inside the container
git config --global --add safe.directory /app/
solves at least part of the issue (possibly all).
You can try it with:
services:
dev:
image: andyaugustin/actions-template-sync:v2.5.2
entrypoint: ["/bin/bash"]
working_dir: /app/
tty: true
volumes:
- .:/app/
environment:
- TARGET_GH_TOKEN="foo"
- SOURCE_GH_TOKEN="bar"
- SOURCE_REPO_PATH="foo"
- GITHUB-SERVER_URL="https://github.com"
- GIT_USER_NAME="abc"
- GIT_USER_EMAIL="[email protected]"
docker compose run dev
Will need some further research and debugging but possibly this part already helps a bit.
@ToshY I think it is actually a bug. To solve it inside the container
git config --global --add safe.directory /app/ solves at least part of the issue (possibly all).
You can try it with:
services: dev: image: andyaugustin/actions-template-sync:v2.5.2 entrypoint: ["/bin/bash"] working_dir: /app/ tty: true volumes: - .:/app/ environment: - TARGET_GH_TOKEN="foo" - SOURCE_GH_TOKEN="bar" - SOURCE_REPO_PATH="foo" - GITHUB-SERVER_URL="https://github.com" - GIT_USER_NAME="abc" - GIT_USER_EMAIL="[email protected]" docker compose run dev Will need some further research and debugging but possibly this part already helps a bit.
@AndreasAugustin This helped very much. I ended up with a trail-and-error approach (with chatgpt) and eventually got it working. In the process, also encountered a bug, for which I will create a PR.
The following command succesfully created a PR in one of the derived template repositories.
[ -f .git/hooks/commit-msg ] && mv .git/hooks/commit-msg .git/hooks/commit-msg.disabled; \
[ -f .git/hooks/pre-commit ] && mv .git/hooks/pre-commit .git/hooks/pre-commit.disabled; \
docker run -it \
-v $(pwd):/app \
--workdir /app \
--rm \
--env TARGET_GH_TOKEN="$(gh auth token)" \
--env SOURCE_GH_TOKEN="$(gh auth token)" \
--env SOURCE_REPO_PATH="<owner/template>" \
--env GITHUB_SERVER_URL="https://github.com" \
--env HOSTNAME="github.com" \
--env SSH_PRIVATE_KEY_SRC="$(cat ~/.ssh/id_ed25519)" \
--env UPSTREAM_BRANCH=main \
--env TEMPLATE_SYNC_IGNORE_FILE_PATH=".templatesyncignore" \
--env IS_FORCE_PUSH_PR=true \
--env PR_COMMIT_MSG="chore: sync template" \
--env PR_TITLE="[chore] upstream merge template repository" \
--env GIT_USER_NAME="ToshY" \
--env GIT_USER_EMAIL="<redacted>" \
--entrypoint "/bin/bash" \
andyaugustin/actions-template-sync:v2.5.2 \
-c "sed -i 's/retun 0/return 0/' /bin/sync_template.sh && git config --global --add safe.directory /app && /bin/entrypoint.sh"; \
[ -f .git/hooks/commit-msg.disabled ] && mv .git/hooks/commit-msg.disabled .git/hooks/commit-msg; \
[ -f .git/hooks/pre-commit.disabled ] && mv .git/hooks/pre-commit.disabled .git/hooks/pre-commit
Some notes regarding running the command above:
- The temporary moving/disabling of the
.git/hooksis required in my case, as my hooks containdockercommand. Please consider adding another env variable, e.g.COMMIT_ARGS, so could be used to pass-nhere: https://github.com/AndreasAugustin/actions-template-sync/blob/4fdac2bc9253e967f41730c7dab7489f1ee5f679/src/sync_template.sh#L502 - The env
HOSTNAMEis required (and set togithub.com), else it will try to use an docker container hostname which leads toerror validating token: Get "https://92828dec57e7/api/v3/": dial tcp 172.18.0.3:443: connect: connection refused - The env
TEMPLATE_SYNC_IGNORE_FILE_PATHis required, else it will give the errorMissing env variable 'TEMPLATE_SYNC_IGNORE_FILE_PATH'. The file doesnt need to exist on the host though. - The env
SSH_PRIVATE_KEY_SRCis required if you use SSH for your remote instead of HTTPS (see the.git/configto verify) - The env
PRE_COMMIT_MSGis required, else it will give the errorMissing env variable 'PR_COMMIT_MSG' - The env
PR_TITLEis required, else it will have pushed the branch but not created a PR, and show warningpull request title must not be blank; ::warn::Creating the PR failed. - The
sed -i 's/retun 0/return 0/' /bin/sync_template.shis a temporary fix for which another PR must be made, as it hasretuninstead ofreturn: https://github.com/AndreasAugustin/actions-template-sync/blob/4fdac2bc9253e967f41730c7dab7489f1ee5f679/src/sync_template.sh#L299-L300- Created PR https://github.com/AndreasAugustin/actions-template-sync/pull/661
Some additional observations:
- After it succesfully executed, I noticed that the branch was still checked out locally (
_0e51840).- One issue is that files were written as
root. This makes sense because I did not pass the user to the docker command. However if I do pass-u $(id -u):$(id -g)to the docker command it immediatly fails and leads to errorerror: could not lock config file //.gitconfig: Permission denied. Is there a way to resolve the permissions issues? I'd rather run this as the current user, and not root, to prevent these file owner permissions issues. - Is it also possible that after the script created the PR, to automatically check out the base branch (
main) again?
- One issue is that files were written as