Skip to content

Commit

Permalink
Support post-startup script in libreoffice devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
cbookg committed Aug 2, 2024
1 parent d1167cc commit 2884d8c
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 24 deletions.
26 changes: 26 additions & 0 deletions features/src/workbench-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Hello, World! (hello)

A hello world feature

## Example Usage

```json
"features": {
"ghcr.io/devcontainers/feature-starter/hello:1": {
"version": "latest"
}
}
```

## Options

| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| greeting | Select a pre-made greeting, or enter your own | string | hey |



---

_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/devcontainers/feature-starter/blob/main/src/hello/devcontainer-feature.json). Add additional notes to a `NOTES.md`._
22 changes: 22 additions & 0 deletions features/src/workbench-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Hello, World!",
"id": "hello",
"version": "1.0.2",
"description": "A hello world feature",
"options": {
"greeting": {
"type": "string",
"proposals": [
"hey",
"hello",
"hi",
"howdy"
],
"default": "hey",
"description": "Select a pre-made greeting, or enter your own"
}
},
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
}
29 changes: 29 additions & 0 deletions features/src/workbench-cli/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
set -e

echo "Activating feature 'hello'"

GREETING=${GREETING:-undefined}
echo "The provided greeting is: $GREETING"

# The 'install.sh' entrypoint script is always executed as the root user.
#
# These following environment variables are passed in by the dev container CLI.
# These may be useful in instances where the context of the final
# remoteUser or containerUser is useful.
# For more details, see https://containers.dev/implementors/features#user-env-var
echo "The effective dev container remoteUser is '$_REMOTE_USER'"
echo "The effective dev container remoteUser's home directory is '$_REMOTE_USER_HOME'"

echo "The effective dev container containerUser is '$_CONTAINER_USER'"
echo "The effective dev container containerUser's home directory is '$_CONTAINER_USER_HOME'"

cat > /usr/local/bin/hello \
<< EOF
#!/bin/sh
RED='\033[0;91m'
NC='\033[0m' # No Color
echo "\${RED}${GREETING}, \$(whoami)!\${NC}"
EOF

chmod +x /usr/local/bin/hello
35 changes: 17 additions & 18 deletions src/libreoffice/.devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@
"service": "app",
"shutdownAction": "none",
"workspaceFolder": "/workspace",
// TODO: Enable this once Linux installation is resolved.
// "postCreateCommand": [
// "./startupscript/post-startup.sh",
// "abc",
// "/config",
// "${templateOption:cloud}",
// "${templateOption:login}"
// ],
// // re-mount bucket files on container start up
// "postStartCommand": [
// "./startupscript/remount-on-restart.sh",
// "abc",
// "/config",
// "${templateOption:cloud}",
// "${templateOption:login}"
// ],
"postCreateCommand": [
"./startupscript/post-startup.sh",
"abc",
"/config",
"gcp",
"true"
],
// re-mount bucket files on container start up
"postStartCommand": [
"./startupscript/remount-on-restart.sh",
"abc",
"/config",
"gcp",
"true"
],
"remoteUser": "root",
"features": {
// TODO: Need to install Java for the CLI, but this feature does not support alpine linux.
// "ghcr.io/devcontainers/features/java:1": {
"./.devcontainer/features/workbench-cli": {}
// "./.devcontainer/features/src/java": {
// "version": "17"
// }
}
Expand Down
1 change: 1 addition & 0 deletions src/libreoffice/.devcontainer/features
2 changes: 1 addition & 1 deletion src/libreoffice/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.0"
version: "2.4"
services:
app:
container_name: "application-server"
Expand Down
4 changes: 2 additions & 2 deletions startupscript/install-java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
# - USER_PRIMARY_GROUP: name of primary group app user belongs to

# Check if the user name is provided.
ln -sf "$(which java)" "/usr/bin"
chown --no-dereference "${USER_NAME}:${USER_PRIMARY_GROUP}" "/usr/bin/java"
#ln -sf "$(which java)" "/usr/bin"
#chown --no-dereference "${USER_NAME}:${USER_PRIMARY_GROUP}" "/usr/bin/java"

10 changes: 7 additions & 3 deletions startupscript/post-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ ${RUN_AS_LOGIN_USER} "ln -sf '${USER_WORKBENCH_CONFIG_DIR}' '${USER_WORKBENCH_LE
exec >> "${POST_STARTUP_OUTPUT_FILE}"
exec 2>&1

# The apt package index may not be clean when we run; resynchronize
apt-get update
apt install -y jq curl fuse tar wget
# Test for apt-get being present.
which apt-get && true
if [[ $? -eq 0 ]]; then
# The apt package index may not be clean when we run; resynchronize
apt-get update
apt install -y jq curl fuse tar wget
fi

# Create the target directories for installing into the HOME directory
${RUN_AS_LOGIN_USER} "mkdir -p '${USER_BASH_COMPLETION_DIR}'"
Expand Down

0 comments on commit 2884d8c

Please sign in to comment.