Skip to content

Commit

Permalink
Mewu/fix issues (#2)
Browse files Browse the repository at this point in the history
* change devcontainer path

* Ignore devcontainer folder changes

* use add to install in current location

* add more checks

* fix wrong arguments

* simplify the postXrate script

* adding docker build job

* workaround for extenion path and use prebuilt image to address slowness

* fix publish index link

* add some delay

* specify port

* use default option
  • Loading branch information
MeWu-IDM authored Oct 1, 2024
1 parent 1f30fe8 commit e00ccac
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 26 deletions.
17 changes: 8 additions & 9 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "Python and R Dev Container",
"build": {
"dockerfile": "../Dockerfile",
"context": "."
},
"image": "mewu/data_access:latest", // Use pre-built image
// "build": {
// "dockerfile": "../Dockerfile",
// "context": ".."
// },
"customizations": {
"vscode": {
"extensions": [
Expand All @@ -25,15 +26,13 @@
// "source=${localWorkspaceFolder},target=/workspaces/${localWorkspaceFolder},type=bind,consistency=cached"
// ],
"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",
"postStartCommand:": "rstudio-server restart && jupyter lab --ip=0.0.0.0 --no-browser --allow-root --NotebookApp.token=''",
"postStartCommand": "bash ./.devcontainer/postStartCommand.sh",
"portsAttributes": {
"8888": {
"label": "Jupyter Lab",
"onAutoForward": "always",
"label": "Jupyter Lab"
},
"8787": {
"label": "R studio",
"onAutoForward": "always"
"label": "R studio"
}
},
"forwardPorts": [8787, 8888]
Expand Down
6 changes: 0 additions & 6 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,4 @@ fi
# cd r && R -e 'renv::restore()'
#fi

# change the default working directory for RStudio
echo "session-default-working-dir=${CODESPACE_VSCODE_FOLDER}" | sudo tee -a /etc/rstudio/rsession.conf

rstudio-server start > rstudio_server.log 2>&1 &
jupyter lab --ip=0.0.0.0 --no-browser --allow-root --NotebookApp.token='' 2>&1 &

echo "Dev environment setup completed!"
25 changes: 25 additions & 0 deletions .devcontainer/postStartCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# change the default working directory for RStudio
echo "session-default-working-dir=${CODESPACE_VSCODE_FOLDER}" | sudo tee -a /etc/rstudio/rsession.conf

# Start RStudio Server
echo "Start R studeio Server"
rstudio-server start > rstudio_server.log 2>&1 &
sleep 5 # Give some time for the service to start
if ! pgrep -x "rstudio-server" > /dev/null; then
echo "RStudio Server failed to start. Restarting..."
rstudio-server restart > rstudio_server.log 2>&1 &
fi

sleep 5
echo "Setup Jupyter-lab"
# Start Jupyter Lab
jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root --NotebookApp.token='' > jupyter_lab.log 2>&1 &
sleep 5
if ! pgrep -x "jupyter-lab" > /dev/null; then
echo "Jupyter Lab failed to start. Restarting..."
jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root --NotebookApp.token='' > jupyter_lab.log 2>&1 &
fi

echo "Dev environment startup completed!"
25 changes: 15 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
paths-ignore:
- '.devcontainer/**'
workflow_dispatch: # Manual trigger

jobs:
Expand All @@ -17,9 +16,9 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Build Docker image
run: |
docker build -t demo-quarto-image .
# - name: Build Docker image
# run: |
# docker build -t demo-quarto-image .

- name: Create gallery directory on the host
run: |
Expand All @@ -29,7 +28,7 @@ jobs:
- name: Run Quarto in Docker container
run: |
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace demo-quarto-image bash -c "
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace mewu/data_access:latest bash -c "
source /opt/venv/bin/activate
echo 'activated virtualenv.'
Expand All @@ -52,6 +51,12 @@ jobs:
echo \"Processing file: \$file\"
# Remove the /workspace prefix from the file path
relative_dir=\$(dirname \"\${file#'/workspace/'}\")
# Install extension to the folder directly
pushd \$relative_dir
/workspace/r/install_quarto_extensions.expect
popd
target_dir=\"/workspace/gallery/\$relative_dir\"
echo \"Creating target directory: \$target_dir\"
mkdir -p \"\$target_dir\" && echo \"Directory \$target_dir created.\"
Expand All @@ -76,11 +81,11 @@ jobs:
run: |
ls -laR gallery
echo "<html><body><h1>Gallery Index</h1><ul>" > gallery/index.html
find gallery -name "*.html" | while read -r file; do
find gallery -name "*.html" -not -name "index.html" | while read -r file; do
# Remove the 'gallery/' prefix from the file path
relative_path="${file#gallery/}"
file_name=$(basename "$file")
echo "<li><a href=\"./$relative_path\">$file_name</a></li>" >> gallery/index.html
echo "<li><a href=\"./$relative_path\">$relative_path</a></li>" >> gallery/index.html
done
echo "</ul></body></html>" >> gallery/index.html
Expand All @@ -100,4 +105,4 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./gallery # Path to the folder that you want to publish (the gallery folder)
publish_branch: docs # The branch used for GitHub Pages
publish_branch: docs # The branch used for GitHub Pages
33 changes: 33 additions & 0 deletions .github/workflows/update_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: update docker image

on:
workflow_dispatch:
inputs:
tags:
description: 'image tags'
required: false
default: mewu/data_access:latest

jobs:
docker:
runs-on: ubuntu-latest
environment: test
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ github.event.inputs.tags }}
2 changes: 1 addition & 1 deletion r/install_quarto_extensions.expect
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/expect

# Start the quarto command
spawn quarto install extension quarto-ext/shinylive
spawn quarto add quarto-ext/shinylive

# Look for the prompt and send "y"
expect "*Do you trust the authors of this extension*" {
Expand Down

0 comments on commit e00ccac

Please sign in to comment.