Remove `git reset --hard` command in web template to reduce layer size (#903)
authorAlan Guo Xiang Tan <gxtan1990@gmail.com>
Mon, 23 Dec 2024 08:52:19 +0000 (16:52 +0800)
committerGitHub <noreply@github.com>
Mon, 23 Dec 2024 08:52:19 +0000 (16:52 +0800)
commit7cd3dce007b91734d49135c663db7ba8ff028902
tree657846f4751ffff8a118c6a34b2186af9b1b8e99
parent2fb389f61dc1fb88f0fb2db991da7f1a290b3afa
Remove `git reset --hard` command in web template to reduce layer size (#903)

I noticed that use running `git reset --hard` results in ~133MB being
added to the final layer generated by `launcher bootstrap`. However, I
can not figure out why we would need to run `git reset --hard` at all.

Even if there is a reason to run `git reset --hard`, it should not be
the default. If someone for whatever reason needs to run `git reset
--hard`, they should do so using the `before_code` hook.

To replicate the problem, one can run the following steps:

1. In the `discourse_docker` repository, create a file named `containers/test.yml` with the following contents:

```
base_image: discourse/base:2.0.20241223-0016

run:
  - exec: sudo -H -E -u discourse bash -c "cd /var/www/discourse && git reset --hard"
```

2. Run `./launcher bootstrap test`
3. Run `docker history local_discourse/test` and see that the new layer created by `./launcher bootstrap` is roughly 133MB.

```
IMAGE          CREATED         CREATED BY                                      SIZE      COMMENT
012471f3c5e4   2 minutes ago   /bin/bash -c /usr/local/bin/pups --stdin        133MB
```
templates/web.template.yml