Skip to content

Commit

Permalink
Merge branch 'devel' into docs/gitpod-update
Browse files Browse the repository at this point in the history
  • Loading branch information
iaine authored Aug 16, 2024
2 parents d149190 + f6c0c2a commit a1223c0
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 110 deletions.
64 changes: 25 additions & 39 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,31 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "R-Dev-Env",
"image": "ghcr.io/r-devel/r-dev-env:main",
"hostRequirements": {
"cpus": 4
},

"customizations": {
"vscode": {
"settings": {
"r.lsp.diagnostics": false,
"r.plot.useHttpgd": true,
"r.rpath.linux": "/usr/bin/R",
"r.rterm.linux": "/usr/bin/R",
"terminal.integrated.sendKeybindingsToShell": true,
"svn.multipleFolders.enabled": true,
"name": "R-Dev-Env",
"image": "ghcr.io/r-devel/r-dev-env:devel",
"hostRequirements": {
"cpus": 4
},
"customizations": {
"vscode": {
"settings": {
"r.lsp.diagnostics": false,
"r.plot.useHttpgd": true,
"r.rpath.linux": "/usr/bin/R",
"r.rterm.linux": "/usr/bin/R",
"terminal.integrated.sendKeybindingsToShell": true,
"svn.multipleFolders.enabled": true,
"workbench.editorAssociations": {
"*.md": "vscode.markdown.preview.editor"
},
"workbench.welcomePage.walkthroughs.openOnInstall": false
},
"extensions": [
"REditorSupport.r",
"mads-hartmann.bash-ide-vscode",
"johnstoncode.svn-scm",
"ms-vscode.cpptools",
"MS-vsliveshare.vsliveshare"
]
}

},
"postCreateCommand":"cat /workspaces/r-dev-env/scripts/welcome_msg.sh >> ~/.bashrc && cat /workspaces/r-dev-env/scripts/set_build_r.sh >> ~/.bashrc && bash /workspaces/r-dev-env/scripts/localscript.sh"
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "gcc -v",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
},
"extensions": [
"REditorSupport.r",
"mads-hartmann.bash-ide-vscode",
"johnstoncode.svn-scm",
"ms-vscode.cpptools",
"MS-vsliveshare.vsliveshare"
]
}
},
"postCreateCommand": "chown -R vscode:vscode /workspaces/r-dev-env && sh /workspaces/r-dev-env/scripts/localscript.sh"
}
4 changes: 3 additions & 1 deletion .github/workflows/build-gitpod-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
paths:
- '.github/workflows/build-gitpod-image.yml'
- '.gitpod.Dockerfile'
- '.gitpod.yml'
- 'reinstall-cmake.sh'
- 'VERSION'

Expand Down Expand Up @@ -59,7 +60,8 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .gitpod.Dockerfile
context: .
file: .gitpod.Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:gitpod.${{ github.ref_name }}
build-args: |
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/optimize-docs-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Optimize Docs Images

on:
pull_request:
branches: ["main","devel"]
types: [closed]
paths:
- 'docs/assets/**'

jobs:
optimize-images:
if: ${{github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true}}
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup R
uses: r-lib/actions/setup-r@v2

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libmagick++-dev
- name: Install R packages
run: |
R -e 'install.packages(c("magick", "tools"), repos = "https://cloud.r-project.org/")'
- name: Optimize images
run: |
Rscript ./scripts/optimize.R
- name: Commit and push optimized images
if: github.ref == 'refs/heads/devel' && github.event_name == 'push'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add docs/assets
git commit -m 'Optimize docs images'
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33 changes: 33 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM gitpod/workspace-full:latest

USER root

ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none"

# Optionally install the cmake for vcpkg
COPY ./reinstall-cmake.sh /tmp/

RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
fi \
&& rm -f /tmp/reinstall-cmake.sh

RUN sed -i.bak "/^#.*deb-src.*universe$/s/^# //g" /etc/apt/sources.list \
&& echo "deb https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/" >> /etc/apt/sources.list \
&& wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc \
&& apt update \
&& apt -y install subversion \
&& apt -y build-dep r-base-dev \
&& apt -y install r-base-dev \
&& Rscript -e "install.packages('languageserver', repos='https://cran.rstudio.com')" \
&& Rscript -e "install.packages('httpgd', repos='https://cran.rstudio.com')"

RUN apt install -y shellcheck
RUN apt install -y ccache
RUN apt install -y rsync
#RUN /usr/sbin/update-ccache-symlinks
#RUN echo 'export PATH="/usr/lib/ccache:$PATH"' | tee -a /home/vscode/.bashrc


ARG CONTAINER_VERSION
ENV CONTAINER_VERSION ${CONTAINER_VERSION}
13 changes: 13 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
image: ghcr.io/r-devel/r-dev-env:gitpod.devel

tasks:
- name: Initial Setup for R-dev-env Gitpod Workspace
before: |
bash /workspace/r-dev-env/scripts/localscript.sh
source ~/.bashrc
vscode:
extensions:
- REditorSupport.r
- johnstoncode.svn-scm
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ RUN apt install -y ccache
#RUN echo 'export PATH="/usr/lib/ccache:$PATH"' | tee -a /home/vscode/.bashrc


ENV BUILDDIR="/workspaces/r-dev-env/build/r-devel"
ENV TOP_SRCDIR="/workspaces/r-dev-env/svn/r-devel"
ENV PATCHDIR='/workspaces/r-dev-env/patches'

ARG CONTAINER_VERSION
ENV CONTAINER_VERSION ${CONTAINER_VERSION}
40 changes: 35 additions & 5 deletions INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
If you haven't seen them yet, you can find the
[R Dev Container Docs](https://contributor.r-project.org/r-dev-env/) online.

## Home
R Development Container [Project overview](docs/index.md)

## Container Setup
Getting Started with R Development Container and setting up Environment like Codespaces, Gitpod and Localsetup.

- R Dev Container usage [overview](docs/container_setup/index.md)

### Github Codespace
1. [Starting Codespace](docs/container_setup/github_codespace/creating_codespace.md)
2. [Restarting and Stopping Codespace](docs/container_setup/github_codespace/codespacestartstop.md)
3. [Collaborating with Live Share](docs/container_setup/github_codespace/live_share.md)


### Gitpod Workspace
1. [Starting Gitpod](docs/container_setup/gitpod_workspace/workspacestart.md)
2. [Restarting and Stopping Workspace](docs/container_setup/gitpod_workspace/workspacestop_and_restart.md)
3. [Collaborating with Live Share](docs/container_setup/gitpod_workspace/live_share.md)

### Local Setup
Documentation for setting up R Dev Container Locally
- [Local Setup](docs/container_setup/local_setup/localsetup.md)

Note: For Now R Dev Container Local setup is recommended for Linux Systems.

## Tutorials

You can also preview the tutorials right here in VSCode, making them easier to work through.
Expand All @@ -19,9 +44,14 @@ You can refer to the remaining sections as needed!
6. [Multiple R versions](docs/tutorials/multi_r_compilation.md)
7. [SVN Help](docs/tutorials/svn_help.md)

## Other Docs

- [Restarting And Stopping Codespace](docs/container_setup/codespacestartstop.md)
- [Collaborating with Live Share]((docs/container_setup/live_share.md))
- [Using R Dev Container Locally](docs/container_setup/localsetup.md)
- [Useful Resources](docs/resources.md)
## Contributor Guide
Contributor Guide to R Dev Container
1. [Documentation](docs/contributor_guide/contributing_to_docs.md)
2. [Codebase](docs/contributor_guide/contributing_to_codebase.md)
## Resources
Extra Resources and Installation Information [Guide](docs/resources.md)

## Troubleshoot Information
Information to troubleshoot rsync on R Dev Container
- [Troubleshoot Docs](docs/troubleshoot.md)
37 changes: 31 additions & 6 deletions scripts/localscript.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
# This script is run after the workspace is created
#!/bin/bash

mkdir -p /home/vscode/.local/bin
local_script(){

# Workspace root is $PWD at the start
WORK_DIR=$PWD
VSCODE_DIR="$WORK_DIR/.vscode"
DEVCONTAINER_JSON="$WORK_DIR/.devcontainer/devcontainer.json"

# Create patch directory in workspace root ($PWD at start)
PATCHDIR="$WORK_DIR/patches"
mkdir -p $PATCHDIR
mkdir -p $VSCODE_DIR

chmod +x /workspaces/r-dev-env/scripts/which_r.sh
chmod +x /workspaces/r-dev-env/scripts/set_build_r.sh
# Copy the which_r and set_build_r function definitions to .bashrc
cat $WORK_DIR/scripts/which_r.sh >> ~/.bashrc
cat $WORK_DIR/scripts/set_build_r.sh >> ~/.bashrc

cp /workspaces/r-dev-env/scripts/which_r.sh /home/vscode/.local/bin/which_r
# cp /workspaces/r-dev-env/scripts/set_build_r.sh /home/vscode/.local/bin/set_build_r
# Copy over the welcome message script to be run when bash terminal starts
cat $WORK_DIR/scripts/welcome_msg.sh >> ~/.bashrc

# remove git directory
#bash ~/.bashrc

# Remove git directory if it exists
rm -rf .git

# copying vscode extension settings from devcontainer json to vscode settings json using jq
if [ -f "$DEVCONTAINER_JSON" ]; then
jq '.customizations.vscode.settings' "$DEVCONTAINER_JSON" > "$VSCODE_DIR/settings.json"
fi


}


# Run the main function
local_script
34 changes: 34 additions & 0 deletions scripts/optimize.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
library(magick)
library(tools)

# Define the directory containing images
image_dir <- file.path("docs", "assets")

# Get all photos in the directory with specified extensions
files <- dir(image_dir, pattern = "\\.(jpeg|jpg|png)$", ignore.case = TRUE)

# Process each file
for (i in seq_along(files)) {
# Read the image
file_path <- file.path(image_dir, files[i])
img <- tryCatch({
image_read(file_path)
}, error = function(e) {
message("Error reading image: ", file_path)
next
})

# Resize the image to 800 px width using Triangle filter for resampling
img <- image_resize(img, geometry_size_pixels(width = 800), filter = "Triangle")


# Define the output path (overwrite original image)
output_path <- file_path

# Write the optimized image (overwrite original image)
tryCatch({
image_write(img, output_path, format = "jpg", quality = 82)
}, error = function(e) {
message("Error writing image: ", output_path)
})
}
4 changes: 2 additions & 2 deletions scripts/set_build_r.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set_build_r() {
echo "TOP_SRCDIR is currently set to $TOP_SRCDIR"
else
NAME=$1
export BUILDDIR="/workspaces/r-dev-env/build/$NAME"
export TOP_SRCDIR="/workspaces/r-dev-env/svn/$NAME"
export BUILDDIR="$WORK_DIR/build/$NAME"
export TOP_SRCDIR="$WORK_DIR/svn/$NAME"
echo "BUILDDIR is now set to $BUILDDIR"
echo "TOP_SRCDIR is now set to $TOP_SRCDIR"
fi
Expand Down
7 changes: 7 additions & 0 deletions scripts/welcome_msg.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# This script is run everytime workspace is started (when bash terminal started)
#!/bin/bash

# define helper environment variables based on workspace root ($PWD at start)
export WORK_DIR=$PWD
export BUILDDIR="$WORK_DIR/build/r-devel"
export TOP_SRCDIR="$WORK_DIR/svn/r-devel"
export PATCHDIR="$WORK_DIR/patches"

# clear the screen before displaying welcome message
clear

Expand Down
Loading

0 comments on commit a1223c0

Please sign in to comment.