Skip to content

Commit

Permalink
feat: better support for composer 1/2
Browse files Browse the repository at this point in the history
feat: default magento 2 version: 2.4.2
chore: optimize docker images slightly
  • Loading branch information
janosmiko committed Feb 13, 2021
1 parent 571a4ee commit 8d32b68
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.18-beta
0.1.19-beta
13 changes: 13 additions & 0 deletions docs/configuration/composer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Composer

### Composer home

Composer home `~/.composer` directory is mounted and shared from your host system to the `php-fpm` container.
This makes possible to share Composer's cache, and your Composer auth configuration between environments.

### Change Composer version from 1.x to 2.x

```
$ reward shell
$ sudo alternatives --config composer
```
2 changes: 1 addition & 1 deletion docs/environments/initializing-shopware.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
``` shell
$ reward shell
$ sudo mv -f /usr/bin/composer2 /usr/bin/composer
$ sudo alternatives --set composer /usr/bin/composer2
$ echo $'const:\n APP_ENV: "dev"\n APP_URL: "https://your-awesome-shopware-project.test"\n DB_HOST: "db"\n DB_NAME: "shopware"\n DB_USER: "app"\n DB_PASSWORD: "app"' > .psh.yaml.override
Expand Down
2 changes: 1 addition & 1 deletion images/.trigger
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2F599715-EB6D-44FF-8A58-01A4B259625E
60EC2869-7C78-4B4B-82E1-417FB5544931
8 changes: 3 additions & 5 deletions images/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ COPY etc/php.d/*.ini /etc/php.d/
COPY etc/php.d/05-additions.ini.template /etc/php.d/

# Install mhsendmail to support routing email through mailhog
RUN mkdir -p /tmp/mhsendmail \
&& cd /tmp/mhsendmail \
&& curl -vLOs https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \
&& chmod +x mhsendmail_linux_amd64 \
&& mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail
RUN curl -vsLo /usr/local/bin/mhsendmail \
https://github.com/mailhog/mhsendmail/releases/latest/download/mhsendmail_linux_amd64 \
&& chmod +x /usr/local/bin/mhsendmail

# Install awscli to support data backfill workflows using S3 storage; segno for QR code generation
RUN pip3 install awscli segno --no-cache-dir
Expand Down
8 changes: 6 additions & 2 deletions images/php/cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ RUN set -eux \

ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /tmp/composer
COPY --from=composer:1 /usr/bin/composer /usr/bin/composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer2
COPY --from=composer:1 /usr/bin/composer /usr/local/bin/composer1
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer2

RUN set -eux \
&& alternatives --install /usr/bin/composer composer /usr/bin/composer1 99 \
&& alternatives --install /usr/bin/composer composer /usr/bin/composer2 1
30 changes: 21 additions & 9 deletions internal/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,27 @@ func bootstrapMagento2() error {
freshInstall := false

composerCommand := "composer"
composerVersion := 1

minimumMagentoVersionForComposer2, _ := version.NewVersion("2.4.2")
if GetMagentoVersion().GreaterThanOrEqual(minimumMagentoVersionForComposer2) {
composerVersion = 2
}

if composerVersion == 2 {
log.Debugln("Setting default Composer version to 2.x")
// Change default Composer Version
composerVersionChangeCommand := append(baseCommand,
`sudo alternatives --set composer /usr/bin/composer2`)

if GetMagentoVersion().GreaterThan(minimumMagentoVersionForComposer2) {
composerCommand = "composer2"
if err := EnvCmd(composerVersionChangeCommand); err != nil {
return err
}
}

// Composer Install
if !IsSkipComposerInstall() {
if !IsNoParallel() {
if IsParallel() && composerVersion != 2 {
if IsDebug() {
composeCommand = append(baseCommand, composerCommand+` global require -vvv --profile hirak/prestissimo`)
} else {
Expand Down Expand Up @@ -145,7 +157,7 @@ func bootstrapMagento2() error {
return err
}

if !IsNoParallel() {
if IsParallel() && composerVersion != 2 {
if IsDebug() {
composeCommand = append(baseCommand, composerCommand+` global remove hirak/prestissimo -vvv --profile`)
} else {
Expand Down Expand Up @@ -491,7 +503,7 @@ func bootstrapMagento1() error {

// Composer Install
if CheckFileExists("composer.json") {
if !IsNoParallel() {
if IsParallel() {
if IsDebug() {
composeCommand = append(baseCommand, `composer global require -vvv --profile hirak/prestissimo`)
} else {
Expand All @@ -513,7 +525,7 @@ func bootstrapMagento1() error {
return err
}

if !IsNoParallel() {
if IsParallel() {
if IsDebug() {
composeCommand = append(baseCommand, `composer global remove hirak/prestissimo -vvv --profile`)
} else {
Expand Down Expand Up @@ -739,12 +751,12 @@ func IsFullBootstrap() bool {
return false
}

func IsNoParallel() bool {
func IsParallel() bool {
if viper.IsSet(AppName + "_composer_no_parallel") {
return viper.GetBool(AppName + "_composer_no_parallel")
return !viper.GetBool(AppName + "_composer_no_parallel")
}

return false
return true
}

func IsSkipComposerInstall() bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func GetMagentoVersionFromViper() *version.Version {
if viper.IsSet(AppName + "_magento_version") {
v, _ = version.NewVersion(viper.GetString(AppName + "_magento_version"))
} else {
v, _ = version.NewVersion("2.4.1")
v, _ = version.NewVersion("2.4.2")
}
}

Expand Down

0 comments on commit 8d32b68

Please sign in to comment.