LoginSignup
0
1

More than 3 years have passed since last update.

curl でダウンロードしつつ任意の場所にtar展開する

Posted at

ruby:2.6.5-slim-stretch のDockerイメージを使い yarn を入れるのに苦労したので記録を残しておきます。

RUN部分の抜粋。

ENV YARN_VERSION=1.22.4
RUN bash -c "curl -sL --compressed https://yarnpkg.com/downloads/${YARN_VERSION}/yarn-v${YARN_VERSION}.tar.gz | tee >(tar zx -C /usr/local/ --strip=1 --wildcards yarn*/bin --no-same-owner --no-same-permissions) | tar zx -C /usr/local/ --strip=1 --wildcards yarn*/lib --no-same-owner --no-same-permissions"

3つのコマンドをパイプで連結した文字列を用意して bash -c "curl..." で実行するようにしています。

はじめに curl を使って指定されたバージョンの yarn を標準出力に表示します。

curl -sL --compressed https://yarnpkg.com/downloads/${YARN_VERSION}/yarn-v${YARN_VERSION}.tar.gz

tee を使い出力先を分岐します。 /usr/local/bin に tar内の */bin 以下を展開します。

| tee >(tar zx -C /usr/local/ --strip=1 --wildcards yarn*/bin --no-same-owner --no-same-permissions)

同様に /usr/local/lib に tar 内の */lib 以下を展開します。

| tar zx -C /usr/local/ --strip=1 --wildcards yarn*/lib --no-same-owner --no-same-permissions

bash -c "" をしているのは、 2つ目の | tee >(tar...) にてプロセス展開を行うためです。

docker build を行う際に sh 環境で実行されるので、プロセス展開部分で、 /bin/sh: 1: Syntax error: "(" unexpected がでてしばらく悩みました…。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1