|
| 1 | +# This development container is designed to run on a CodeSpace. |
| 2 | + |
| 3 | +**Contrary to the default container this development container doesn't run a `postCreateCommand`. So when the container is done loading you can start the `hugo server` command with the parameters of your liking.** |
| 4 | + |
| 5 | +A few helpful notes... |
| 6 | + |
| 7 | +## Run `development` configuration as CodeSpace from GitHub |
| 8 | + |
| 9 | +When you Create the codespace, use the options (the three dots: **...**) rather than the default to main (the plus sign **+**) |
| 10 | + |
| 11 | +<img width="691" alt="image" src="https://github.com/user-attachments/assets/faa6862a-4565-4d7e-b721-db3904d723d5"> |
| 12 | + |
| 13 | +Then in the form flip the Dev Container Configuration option to `Development` |
| 14 | + |
| 15 | +<img width="793" alt="image" src="https://github.com/user-attachments/assets/4502d58a-a141-49d1-bcff-bdcc9612b032"> |
| 16 | + |
| 17 | +## Build and serve |
| 18 | + |
| 19 | +You run `hugo serve` to build and serve the website, but you need to tweak a few parameters to make i compliant with the codespace environment: |
| 20 | + |
| 21 | +In the `hugo serve` command the parameters `--baseURL`, `--appendPort` and `--port` are all required for compliancy with a GitHub codespace. |
| 22 | + |
| 23 | +Execute the following command in the terminal and you'll be fine: |
| 24 | + |
| 25 | +```shell |
| 26 | +hugo server \ |
| 27 | + --port 1313 \ |
| 28 | + --bind=0.0.0.0 \ |
| 29 | + -D \ |
| 30 | + -F \ |
| 31 | + -liveReloadPort=443 \ |
| 32 | + --logLevel=debug |
| 33 | + --appendPort=false \ |
| 34 | + --baseURL https://$CODESPACE_NAME-1313.$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN |
| 35 | +``` |
| 36 | + |
| 37 | +Run `hugo --help` to lean a ton of other options you can apply to tweek the development to your liking. Especially these two may prove themselves useful. |
| 38 | + |
| 39 | +``` |
| 40 | + -D, --buildDrafts include content marked as draft |
| 41 | + -F, --buildFuture include content with publishdate in the future |
| 42 | +``` |
| 43 | + |
| 44 | +## When the port hangs |
| 45 | +When you kill the command `hugo serve` it should tear down and release the port as well. Occasionally that doesn't happen. Which means that the port `1313` is bound and you can't strt the command again on port `1313`. Instead you get an error: |
| 46 | + |
| 47 | +```shell |
| 48 | +Error: command error: server startup failed: listen tcp 127.0.0.1:1313: bind: address already in use |
| 49 | +``` |
| 50 | + |
| 51 | +When that happens run the following command to learn which process is listening to the port: |
| 52 | + |
| 53 | +```shell |
| 54 | +netstat -pna | grep "1313" |
| 55 | +``` |
| 56 | + |
| 57 | +It will reveal the process like this: |
| 58 | + |
| 59 | +```shell |
| 60 | +tcp6 0 0 :::1313 :::* LISTEN 19729/hugo |
| 61 | +``` |
| 62 | +In this case PID `19729`. |
| 63 | + |
| 64 | +Now simply kill it (e.g. `kill 19729`) and the port is released. |
| 65 | + |
0 commit comments