-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: docker setup using devcontainer
- Loading branch information
Showing
13 changed files
with
305 additions
and
540 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
ARG TAG=latest | ||
FROM --platform=linux/amd64 ghcr.io/mcanouil/eggla:${TAG} | ||
ARG VARIANT="bullseye" | ||
FROM --platform=linux/amd64 buildpack-deps:${VARIANT}-curl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "BCFtools", | ||
"id": "bcftools", | ||
"version": "1.0.0", | ||
"description": "Installs the BCFtools software.", | ||
"documentationURL": "https://github.com/mcanouil/eggla/tree/main/.devcontainer/bcftools", | ||
"options": { | ||
"version": { | ||
"type": "string", | ||
"proposals": [ | ||
"latest" | ||
], | ||
"default": "latest", | ||
"description": "Select version of the BCFtools software, if not 'latest'." | ||
} | ||
}, | ||
"installsAfter": [ | ||
"ghcr.io/devcontainers/features/common-utils" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env bash | ||
|
||
BCFTOOLS_VERSION=${VERSION:-"1.16"} | ||
|
||
set -e | ||
|
||
apt_get_update() { | ||
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then | ||
echo "Running apt-get update..." | ||
apt-get update -y | ||
fi | ||
} | ||
|
||
# Checks if packages are installed and installs them if not | ||
check_packages() { | ||
if ! dpkg -s "$@" >/dev/null 2>&1; then | ||
apt_get_update | ||
apt-get -y install --no-install-recommends "$@" | ||
fi | ||
} | ||
|
||
check_packages curl \ | ||
build-essential \ | ||
libcurl4-openssl-dev \ | ||
ca-certificates \ | ||
bash-completion \ | ||
gzip \ | ||
libxt6 \ | ||
bzip2 \ | ||
wget \ | ||
autoconf \ | ||
automake \ | ||
make \ | ||
cmake \ | ||
libbz2-dev \ | ||
liblzma-dev \ | ||
libjpeg-dev \ | ||
libxml2-dev \ | ||
zlib1g-dev | ||
|
||
wget -q -P /tmp/ https://github.com/samtools/bcftools/releases/download/${BCFTOOLS_VERSION}/bcftools-${BCFTOOLS_VERSION}.tar.bz2 | ||
tar -C /tmp/ -xjf /tmp/bcftools-${BCFTOOLS_VERSION}.tar.bz2 | ||
cd /tmp/bcftools-${BCFTOOLS_VERSION} | ||
autoreconf -i | ||
./configure --prefix=/usr | ||
make | ||
make install | ||
rm -rf /tmp/bcftools-${BCFTOOLS_VERSION} | ||
|
||
# Clean up | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
echo "Done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "eggla", | ||
"id": "eggla", | ||
"version": "1.0.0", | ||
"description": "Installs the eggla R package.", | ||
"documentationURL": "https://github.com/mcanouil/eggla/tree/main/.devcontainer/eggla", | ||
"options": { | ||
"version": { | ||
"type": "string", | ||
"proposals": [ | ||
"latest" | ||
], | ||
"default": "latest", | ||
"description": "Select version of the eggla R package, if not 'latest'." | ||
} | ||
}, | ||
"installsAfter": [ | ||
"ghcr.io/devcontainers/features/common-utils", | ||
"ghcr.io/rocker-org/devcontainer-features/r-rig" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
USERNAME=${USERNAME:-${_REMOTE_USER:-"automatic"}} | ||
EGGLA_VERSION=${VERSION:-"main"} | ||
|
||
FEATURE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
set -e | ||
|
||
# Determine the appropriate non-root user | ||
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then | ||
USERNAME="" | ||
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)") | ||
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do | ||
if id -u "${CURRENT_USER}" >/dev/null 2>&1; then | ||
USERNAME=${CURRENT_USER} | ||
break | ||
fi | ||
done | ||
if [ "${USERNAME}" = "" ]; then | ||
USERNAME=root | ||
fi | ||
elif [ "${USERNAME}" = "none" ] || ! id -u "${USERNAME}" >/dev/null 2>&1; then | ||
USERNAME=root | ||
fi | ||
|
||
if [ "${USERNAME}" = "root" ]; then | ||
user_home="/root" | ||
# Check if user already has a home directory other than /home/${USERNAME} | ||
elif [ "/home/${USERNAME}" != $( getent passwd $USERNAME | cut -d: -f6 ) ]; then | ||
user_home=$( getent passwd $USERNAME | cut -d: -f6 ) | ||
else | ||
user_home="/home/${USERNAME}" | ||
if [ ! -d "${user_home}" ]; then | ||
mkdir -p "${user_home}" | ||
chown ${USERNAME}:${group_name} "${user_home}" | ||
fi | ||
fi | ||
|
||
apt_get_update() { | ||
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then | ||
echo "Running apt-get update..." | ||
apt-get update -y | ||
fi | ||
} | ||
|
||
# Checks if packages are installed and installs them if not | ||
check_packages() { | ||
if ! dpkg -s "$@" >/dev/null 2>&1; then | ||
apt_get_update | ||
apt-get -y install --no-install-recommends "$@" | ||
fi | ||
} | ||
|
||
check_packages curl \ | ||
build-essential \ | ||
libcurl4-openssl-dev \ | ||
ca-certificates \ | ||
bash-completion \ | ||
gzip \ | ||
libxt6 \ | ||
bzip2 \ | ||
wget \ | ||
autoconf \ | ||
automake \ | ||
make \ | ||
cmake \ | ||
libbz2-dev \ | ||
liblzma-dev \ | ||
libjpeg-dev \ | ||
libxml2-dev \ | ||
zlib1g-dev \ | ||
libgdal-dev \ | ||
libfontconfig1-dev \ | ||
libharfbuzz-dev \ | ||
libfribidi-dev \ | ||
libv8-dev \ | ||
libudunits2-dev \ | ||
libfftw3-dev | ||
|
||
install_pak() { | ||
local version=$1 | ||
|
||
if [ "${version}" = "auto" ]; then | ||
if su "${USERNAME}" -c "R -s -e 'packageVersion(\"pak\")'" >/dev/null 2>&1; then | ||
echo "pak is already installed. Skip pak installation..." | ||
return | ||
else | ||
version="devel" | ||
fi | ||
fi | ||
|
||
echo "Installing pak ${version}..." | ||
# shellcheck disable=SC2016 | ||
su "${USERNAME}" -c 'R -q -e "install.packages(\"pak\", repos = sprintf(\"https://r-lib.github.io/p/pak/'"${version}"'/%s/%s/%s\", .Platform\$pkgType, R.Version()\$os, R.Version()\$arch))"' | ||
} | ||
|
||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
echo "Install R packages..." | ||
mkdir /tmp/r-packages | ||
pushd /tmp/r-packages | ||
|
||
install_pak "auto" | ||
|
||
su "${USERNAME}" -c "R -q -e \"pak::lockfile_install(update = TRUE)\"" | ||
|
||
if [ "${EGGLA_VERSION}" = "main" ]; then | ||
su "${USERNAME}" -c "R -q -e \"pak::pkg_install('mcanouil/eggla', upgrade = FALSE, dependencies = TRUE)\"" | ||
else | ||
su "${USERNAME}" -c "R -q -e \"pak::pkg_install('mcanouil/eggla@${EGGLA_VERSION}', upgrade = FALSE, dependencies = TRUE)\"" | ||
fi | ||
|
||
su "${USERNAME}" -c "R -q -e \"pak::cache_clean()\"" | ||
|
||
cp ${FEATURE_DIR}/tests/eggla-example.R ${user_home}/eggla-example.R | ||
chmod +x ${user_home}/eggla-example.R | ||
|
||
cp ${FEATURE_DIR}/bin/plink2 /usr/bin/plink2 | ||
chmod +x /usr/bin/plink2 | ||
|
||
popd | ||
rm -rf /tmp/r-packages | ||
rm -rf /tmp/Rtmp* | ||
|
||
echo "Done!" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Build & Test Docker Image | ||
|
||
on: | ||
workflow_dispatch: | ||
workflow_run: | ||
workflows: "R-CMD-check" | ||
branches: main | ||
types: completed | ||
release: | ||
types: [published] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build-docker: | ||
runs-on: ubuntu-latest | ||
if: | | ||
github.event_name == 'workflow_dispatch' || | ||
github.event_name == 'release' || | ||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') | ||
strategy: | ||
fail-fast: false | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and run Dev Container | ||
uses: devcontainers/[email protected] | ||
if: github.ref_name == 'main' | ||
with: | ||
subFolder: .github | ||
imageName: ghcr.io/mcanouil/eggla | ||
cacheFrom: ghcr.io/mcanouil/eggla | ||
imageTag: ${{github.ref_name}} | ||
platform: linux/amd64 | ||
push: always | ||
runCmd: Rscript eggla-example.R | ||
|
||
- name: Build and run Dev Container | ||
uses: devcontainers/[email protected] | ||
if: github.ref_name != 'main' | ||
with: | ||
subFolder: .github | ||
imageName: ghcr.io/mcanouil/eggla | ||
cacheFrom: ghcr.io/mcanouil/eggla | ||
imageTag: "devel" | ||
platform: linux/amd64 | ||
push: always | ||
runCmd: Rscript eggla-example.R |
Oops, something went wrong.