Skip to content

Commit 13f55ef

Browse files
authored
Merge pull request laradock#1387 from CantonBolo/optimize
Support custom composer repo url and npm registry url
2 parents 715c217 + 43bf67b commit 13f55ef

6 files changed

Lines changed: 82 additions & 0 deletions

File tree

DOCUMENTATION/content/documentation/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,3 +1729,13 @@ This error sometimes happens because your Laravel application isn't running on t
17291729
## I get stuck when building nginx on `fetch http://mirrors.aliyun.com/alpine/v3.5/main/x86_64/APKINDEX.tar.gz`
17301730

17311731
As stated on [#749](https://github.com/laradock/laradock/issues/749#issuecomment-293296687), removing the line `RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories` from `nginx/Dockerfile` solves the problem.
1732+
1733+
## Custom composer repo packagist url and npm registry url
1734+
1735+
In China, the origin source of composer and npm is very slow. You can add `WORKSPACE_NPM_REGISTRY` and `WORKSPACE_COMPOSER_REPO_PACKAGIST` config in `.env` to use your custom source.
1736+
1737+
Example:
1738+
```bash
1739+
WORKSPACE_NPM_REGISTRY=https://registry.npm.taobao.org
1740+
WORKSPACE_COMPOSER_REPO_PACKAGIST=https://packagist.phpcomposer.com
1741+
```

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ services:
2323
- INSTALL_PHPREDIS=${WORKSPACE_INSTALL_PHPREDIS}
2424
- INSTALL_MSSQL=${WORKSPACE_INSTALL_MSSQL}
2525
- INSTALL_NODE=${WORKSPACE_INSTALL_NODE}
26+
- NPM_REGISTRY=${WORKSPACE_NPM_REGISTRY}
2627
- INSTALL_YARN=${WORKSPACE_INSTALL_YARN}
2728
- INSTALL_DRUSH=${WORKSPACE_INSTALL_DRUSH}
2829
- INSTALL_DRUPAL_CONSOLE=${WORKSPACE_INSTALL_DRUPAL_CONSOLE}
2930
- INSTALL_AEROSPIKE=${WORKSPACE_INSTALL_AEROSPIKE}
3031
- INSTALL_V8JS=${WORKSPACE_INSTALL_V8JS}
3132
- COMPOSER_GLOBAL_INSTALL=${WORKSPACE_COMPOSER_GLOBAL_INSTALL}
33+
- COMPOSER_REPO_PACKAGIST=${WORKSPACE_COMPOSER_REPO_PACKAGIST}
3234
- INSTALL_WORKSPACE_SSH=${WORKSPACE_INSTALL_WORKSPACE_SSH}
3335
- INSTALL_LARAVEL_ENVOY=${WORKSPACE_INSTALL_LARAVEL_ENVOY}
3436
- INSTALL_LARAVEL_INSTALLER=${WORKSPACE_INSTALL_LARAVEL_INSTALLER}

env-example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ WORKSPACE_INSTALL_AMQP=false
6767
WORKSPACE_INSTALL_PHPREDIS=false
6868
WORKSPACE_INSTALL_MSSQL=false
6969
WORKSPACE_INSTALL_NODE=false
70+
WORKSPACE_NPM_REGISTRY=
7071
WORKSPACE_INSTALL_YARN=false
7172
WORKSPACE_INSTALL_DRUSH=false
7273
WORKSPACE_INSTALL_DRUPAL_CONSOLE=false
7374
WORKSPACE_INSTALL_AEROSPIKE=false
7475
WORKSPACE_INSTALL_V8JS=false
7576
WORKSPACE_COMPOSER_GLOBAL_INSTALL=false
77+
WORKSPACE_COMPOSER_REPO_PACKAGIST=
7678
WORKSPACE_INSTALL_WORKSPACE_SSH=false
7779
WORKSPACE_INSTALL_LARAVEL_ENVOY=false
7880
WORKSPACE_INSTALL_LARAVEL_INSTALLER=false

workspace/Dockerfile-56

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ RUN if [ ${COMPOSER_GLOBAL_INSTALL} = true ]; then \
127127
composer global install \
128128
;fi
129129

130+
ARG COMPOSER_REPO_PACKAGIST
131+
ENV COMPOSER_REPO_PACKAGIST ${COMPOSER_REPO_PACKAGIST}
132+
133+
RUN if [ ${COMPOSER_REPO_PACKAGIST} ]; then \
134+
composer config -g repo.packagist composer ${COMPOSER_REPO_PACKAGIST} \
135+
;fi
136+
130137
# Export composer vendor path
131138
RUN echo "" >> ~/.bashrc && \
132139
echo 'export PATH="~/.composer/vendor/bin:$PATH"' >> ~/.bashrc
@@ -309,6 +316,8 @@ ARG NODE_VERSION=stable
309316
ENV NODE_VERSION ${NODE_VERSION}
310317
ARG INSTALL_NODE=false
311318
ENV INSTALL_NODE ${INSTALL_NODE}
319+
ARG NPM_REGISTRY
320+
ENV NPM_REGISTRY ${NPM_REGISTRY}
312321
ENV NVM_DIR /home/laradock/.nvm
313322
RUN if [ ${INSTALL_NODE} = true ]; then \
314323
# Install nvm (A Node Version Manager)
@@ -317,6 +326,9 @@ RUN if [ ${INSTALL_NODE} = true ]; then \
317326
nvm install ${NODE_VERSION} && \
318327
nvm use ${NODE_VERSION} && \
319328
nvm alias ${NODE_VERSION} && \
329+
if [ ${NPM_REGISTRY} ]; then \
330+
npm config set registry ${NPM_REGISTRY} \
331+
;fi && \
320332
npm install -g gulp bower vue-cli \
321333
;fi
322334

@@ -340,6 +352,10 @@ RUN if [ ${INSTALL_NODE} = true ]; then \
340352
# Add PATH for node
341353
ENV PATH $PATH:$NVM_DIR/versions/node/v${NODE_VERSION}/bin
342354

355+
RUN if [ ${NPM_REGISTRY} ]; then \
356+
. ~/.bashrc && npm config set registry ${NPM_REGISTRY} \
357+
;fi
358+
343359
#####################################
344360
# YARN:
345361
#####################################
@@ -428,6 +444,13 @@ RUN if [ ${INSTALL_LARAVEL_ENVOY} = true ]; then \
428444
#####################################
429445
USER root
430446

447+
ARG COMPOSER_REPO_PACKAGIST
448+
ENV COMPOSER_REPO_PACKAGIST ${COMPOSER_REPO_PACKAGIST}
449+
450+
RUN if [ ${COMPOSER_REPO_PACKAGIST} ]; then \
451+
composer config -g repo.packagist composer ${COMPOSER_REPO_PACKAGIST} \
452+
;fi
453+
431454
ARG INSTALL_LARAVEL_INSTALLER=true
432455
ENV INSTALL_LARAVEL_INSTALLER ${INSTALL_LARAVEL_INSTALLER}
433456

workspace/Dockerfile-70

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ RUN if [ ${COMPOSER_GLOBAL_INSTALL} = true ]; then \
124124
composer global install \
125125
;fi
126126

127+
ARG COMPOSER_REPO_PACKAGIST
128+
ENV COMPOSER_REPO_PACKAGIST ${COMPOSER_REPO_PACKAGIST}
129+
130+
RUN if [ ${COMPOSER_REPO_PACKAGIST} ]; then \
131+
composer config -g repo.packagist composer ${COMPOSER_REPO_PACKAGIST} \
132+
;fi
133+
127134
# Export composer vendor path
128135
RUN echo "" >> ~/.bashrc && \
129136
echo 'export PATH="~/.composer/vendor/bin:$PATH"' >> ~/.bashrc
@@ -305,6 +312,8 @@ ARG NODE_VERSION=stable
305312
ENV NODE_VERSION ${NODE_VERSION}
306313
ARG INSTALL_NODE=false
307314
ENV INSTALL_NODE ${INSTALL_NODE}
315+
ARG NPM_REGISTRY
316+
ENV NPM_REGISTRY ${NPM_REGISTRY}
308317
ENV NVM_DIR /home/laradock/.nvm
309318
RUN if [ ${INSTALL_NODE} = true ]; then \
310319
# Install nvm (A Node Version Manager)
@@ -313,6 +322,9 @@ RUN if [ ${INSTALL_NODE} = true ]; then \
313322
nvm install ${NODE_VERSION} && \
314323
nvm use ${NODE_VERSION} && \
315324
nvm alias ${NODE_VERSION} && \
325+
if [ ${NPM_REGISTRY} ]; then \
326+
npm config set registry ${NPM_REGISTRY} \
327+
;fi && \
316328
npm install -g gulp bower vue-cli \
317329
;fi
318330

@@ -336,6 +348,10 @@ RUN if [ ${INSTALL_NODE} = true ]; then \
336348
# Add PATH for node
337349
ENV PATH $PATH:$NVM_DIR/versions/node/v${NODE_VERSION}/bin
338350

351+
RUN if [ ${NPM_REGISTRY} ]; then \
352+
. ~/.bashrc && npm config set registry ${NPM_REGISTRY} \
353+
;fi
354+
339355
#####################################
340356
# YARN:
341357
#####################################
@@ -441,6 +457,13 @@ RUN if [ ${INSTALL_LARAVEL_ENVOY} = true ]; then \
441457
#####################################
442458
USER root
443459

460+
ARG COMPOSER_REPO_PACKAGIST
461+
ENV COMPOSER_REPO_PACKAGIST ${COMPOSER_REPO_PACKAGIST}
462+
463+
RUN if [ ${COMPOSER_REPO_PACKAGIST} ]; then \
464+
composer config -g repo.packagist composer ${COMPOSER_REPO_PACKAGIST} \
465+
;fi
466+
444467
ARG INSTALL_LARAVEL_INSTALLER=true
445468
ENV INSTALL_LARAVEL_INSTALLER ${INSTALL_LARAVEL_INSTALLER}
446469

workspace/Dockerfile-71

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ RUN if [ ${COMPOSER_GLOBAL_INSTALL} = true ]; then \
123123
composer global install \
124124
;fi
125125

126+
ARG COMPOSER_REPO_PACKAGIST
127+
ENV COMPOSER_REPO_PACKAGIST ${COMPOSER_REPO_PACKAGIST}
128+
129+
RUN if [ ${COMPOSER_REPO_PACKAGIST} ]; then \
130+
composer config -g repo.packagist composer ${COMPOSER_REPO_PACKAGIST} \
131+
;fi
132+
126133
#####################################
127134
# Crontab
128135
#####################################
@@ -301,6 +308,8 @@ ARG NODE_VERSION=stable
301308
ENV NODE_VERSION ${NODE_VERSION}
302309
ARG INSTALL_NODE=false
303310
ENV INSTALL_NODE ${INSTALL_NODE}
311+
ARG NPM_REGISTRY
312+
ENV NPM_REGISTRY ${NPM_REGISTRY}
304313
ENV NVM_DIR /home/laradock/.nvm
305314
RUN if [ ${INSTALL_NODE} = true ]; then \
306315
# Install nvm (A Node Version Manager)
@@ -309,6 +318,9 @@ RUN if [ ${INSTALL_NODE} = true ]; then \
309318
nvm install ${NODE_VERSION} && \
310319
nvm use ${NODE_VERSION} && \
311320
nvm alias ${NODE_VERSION} && \
321+
if [ ${NPM_REGISTRY} ]; then \
322+
npm config set registry ${NPM_REGISTRY} \
323+
;fi && \
312324
npm install -g gulp bower vue-cli \
313325
;fi
314326

@@ -332,6 +344,9 @@ RUN if [ ${INSTALL_NODE} = true ]; then \
332344
# Add PATH for node
333345
ENV PATH $PATH:$NVM_DIR/versions/node/v${NODE_VERSION}/bin
334346

347+
RUN if [ ${NPM_REGISTRY} ]; then \
348+
. ~/.bashrc && npm config set registry ${NPM_REGISTRY} \
349+
;fi
335350

336351
#####################################
337352
# YARN:
@@ -442,6 +457,13 @@ RUN if [ ${INSTALL_LARAVEL_ENVOY} = true ]; then \
442457
#####################################
443458
USER root
444459

460+
ARG COMPOSER_REPO_PACKAGIST
461+
ENV COMPOSER_REPO_PACKAGIST ${COMPOSER_REPO_PACKAGIST}
462+
463+
RUN if [ ${COMPOSER_REPO_PACKAGIST} ]; then \
464+
composer config -g repo.packagist composer ${COMPOSER_REPO_PACKAGIST} \
465+
;fi
466+
445467
ARG INSTALL_LARAVEL_INSTALLER=false
446468
ENV INSTALL_LARAVEL_INSTALLER ${INSTALL_LARAVEL_INSTALLER}
447469

0 commit comments

Comments
 (0)