Last active
May 6, 2019 15:51
-
-
Save sgykfjsm/f035d2cf76dea4fbc9fd49a3d7492c28 to your computer and use it in GitHub Desktop.
circleciのカスタムビルダーイメージにperlをインストールするやつ
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
FROM circleci/build-image:enterprise-base | |
# Languages | |
ARG use_precompile=true | |
ENV USE_PRECOMPILE $use_precompile | |
ADD circleci-provision-scripts/perl.sh /opt/circleci-provision-scripts/perl.sh | |
ADD circleci-provision-scripts/circleci-perl-5.24.0_0.0.1_amd64.deb /opt/circleci-provision-scripts/circleci-perl-5.24.0_amd64.deb | |
RUN circleci-install perl 5.24.0 | |
RUN sudo -H -i -u ubuntu plenv global 5.24.0 |
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
#!/bin/bash | |
function install_plenv() { | |
echo '>>> Installing perl' | |
apt-get update -y | |
apt-get install -y git | |
echo 'Installing plenv' | |
(cat <<'EOF' | |
set -ex | |
git clone https://github.com/tokuhirom/plenv.git $CIRCLECI_PKG_DIR/.plenv | |
git clone https://github.com/tokuhirom/Perl-Build.git $CIRCLECI_PKG_DIR/.plenv/plugins/perl-build/ | |
echo "export PLENV_ROOT=$CIRCLECI_PKG_DIR/.plenv" >> ~/.circlerc | |
echo 'export PATH=$PLENV_ROOT/bin:$PATH' >> ~/.circlerc | |
echo 'eval "$(plenv init -)"' >> ~/.circlerc | |
EOF | |
) | as_user CIRCLECI_PKG_DIR=$CIRCLECI_PKG_DIR bash | |
if [ -n "${USE_PRECOMPILE}" ]; then | |
# Preparing for hooking up packaged perl into plenv directories | |
(cat <<'EOF' | |
set -ex | |
mkdir $CIRCLECI_PKG_DIR/perl | |
ln -s $CIRCLECI_PKG_DIR/perl $CIRCLECI_PKG_DIR/.plenv/versions | |
EOF | |
) | as_user CIRCLECI_PKG_DIR=$CIRCLECI_PKG_DIR bash | |
fi | |
} | |
function install_perl_version_plenv() { | |
PERL_VERSION=$1 | |
(cat <<'EOF' | |
set -ex | |
source ~/.circlerc | |
plenv install $PERL_VERSION | |
plenv global $PERL_VERSION | |
plenv rehash | |
plenv install-cpanm | |
plenv exec cpanm --notest Carton Server::Starter | |
EOF | |
) | as_user perl_VERSION=$perl_VERSION bash | |
} | |
function install_perl_version_precompile() { | |
local PERL_VERSION=$1 | |
local deb="/opt/circleci-provision-scripts/circleci-perl-${PERL_VERSION}_amd64.deb" | |
if [ -f "$deb" ]; then | |
dpkg -i /opt/circleci-provision-scripts/circleci-perl-${PERL_VERSION}_amd64.deb | |
chown -R $CIRCLECI_USER:$CIRCLECI_USER $CIRCLECI_PKG_DIR/perl | |
else | |
install_perl_version_plenv $PERL_VERSION | |
fi | |
} | |
function set_perl_default() { | |
local PERL_VERSION=$1 | |
(cat <<'EOF' | |
set -ex | |
source ~/.circlerc | |
plenv global $PERL_VERSION | |
plenv rehash | |
EOF | |
) | as_user PERL_VERSION=$perl_VERSION bash | |
} | |
function install_perl_version() { | |
local VERSION=$1 | |
if [ -n "$USE_PRECOMPILE" ]; then | |
install_perl_version_precompile $VERSION | |
else | |
install_perl_version_plenv $VERSION | |
fi | |
} | |
function install_perl() { | |
local VERSION=$1 | |
[[ -e $CIRCLECI_PKG_DIR/.plenv ]] || install_plenv | |
install_perl_version $1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment