Skip to content

Commit

Permalink
feat: full support for pwa-studio
Browse files Browse the repository at this point in the history
feat: add github build for node images
fix: fix an issue with reading templates from apphome or cwd
  • Loading branch information
janosmiko committed Feb 9, 2021
1 parent 093852b commit fd76561
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 22 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/docker-image-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Docker Image Node
on:
schedule:
- cron: "0 6 1 * *"
push:
paths:
- images/.trigger
- images/node/**
branches:
- main
jobs:
node:
name: Node
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: ./images/scripts/build.sh --push "${BUILD_GROUP}"
env:
BUILD_GROUP: node
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Reward was created under the aegis of [ITG Commerce](https://itgcommerce.com).
- Reward issued wildcard SSL certificates for running https on all local development domains.
- A common PHPMyAdmin container for database management.
- An ElasticHQ container for the ability to manage the Elasticsearch Clusters.
- Full support for Magento 1, Magento 2, Laravel, Symfony 4, Shopware 6 and Wordpress on all major operating systems
- Full support for Magento 1, Magento 2, PWA Studio, Laravel, Symfony 4, Shopware 6 and Wordpress on all major operating systems
- Ability to override, extend, or setup completely custom environment definitions on a per-project basis.

<!-- include_open_stop -->
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.9-beta
0.1.10-beta
1 change: 1 addition & 0 deletions docs/environments/initializing-magento1.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

``` shell
$ git clone git://github.com/your-user/your-awesome-m1-project.git ~/Sites/your-awesome-m1-project
$ cd ~/Sites/your-awesome-m1-project
$ reward env-init your-awesome-m2-project --environment-type=magento1
```

Expand Down
1 change: 1 addition & 0 deletions docs/environments/initializing-magento2.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ It's pretty easy to bootstrap a Magento 2 project using Reward.

``` shell
$ git clone git://github.com/your-user/your-awesome-m2-project.git ~/Sites/your-awesome-m2-project
$ cd ~/Sites/your-awesome-m2-project
$ reward env-init your-awesome-m2-project
```

Expand Down
66 changes: 66 additions & 0 deletions docs/environments/initializing-pwa-studio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
### Initializing PWA Studio

#### Running Default PWA Studio

1. Clone your project and initialize Reward.

``` shell
$ git clone https://github.com/magento/pwa-studio.git ~/Sites/pwa-studio
$ cd ~/Sites/pwa-studio
$ reward env-init pwa-studio --environment-type=pwa-studio
```

2. Sign a certificate for your project

```
$ reward sign-certificate pwa-studio.test
```


3. Fill up the `.env` file with samples and change some settings

``` shell
$ cat docker/.env.docker.dev >> .env
```

``` shell
NODE_VERSION=12
DEV_SERVER_HOST=0.0.0.0
DEV_SERVER_PORT=8000
```

4. Update `package.json` and add these to the scripts part

```
"watch": "yarn watch:venia --disable-host-check",
"start": " yarn stage:venia --disable-host-check"
```

5. Bring up the environment

```
$ reward env up
```

6. Install its dependencies

```
$ reward shell
$ yarn install
```

7. Restart the PWA container

```
$ reward env restart
```

8. Optional: if you'd like to run the project in Developer/Production mode, add the following line to your `.env` file
```
# Developer Mode (default)
DOCKER_START_COMMAND="yarn watch"
# Production Mode
DOCKER_START_COMMAND="yarn start"
```
1 change: 1 addition & 0 deletions docs/environments/initializing-wordpress.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ It's pretty easy to bootstrap a Wordpress project using Reward.
``` shell
$ git clone git://github.com/your-user/your-awesome-wordpress-project.git ~/Sites/your-awesome-wordpress-project
$ cd ~/Sites/your-awesome-wordpress-project
$ reward env-init your-awesome-wordpress-project
```
Expand Down
9 changes: 8 additions & 1 deletion docs/environments/types.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
### Environment Types

Reward currently supports 7 environment types.
Reward currently supports 8 environment types.
* Magento 1
* Magento 2
* PWA Studio (for Magento 2)
* Local
* Laravel
* Symfony
Expand Down Expand Up @@ -38,6 +39,12 @@ The `magento2` environment type provides necessary containerized services for ru

In order to achieve a well performing experience on macOS and Windows, files in the webroot are synced into the container using a Mutagen sync session except `pub/media` which remains mounted using a delegated mount.

#### PWA Studio

The `pwa-studio` environment type provides necessary containerized services for running PWA in a local development context including:

* NodeJS (with yarn)

#### Local

The `local` environment type does nothing more than declare the `docker-compose` version and label the project
Expand Down
4 changes: 3 additions & 1 deletion images/node/10/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM node:10-alpine

ARG DOCKER_START_COMMAND="yarn watch"

RUN apk add --no-cache --virtual .build-deps \
python \
make \
Expand All @@ -13,7 +15,7 @@ RUN apk add --no-cache --virtual .build-deps \
&& chown node:node /usr/src/app

ENV GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
ENV DOCKER_START_COMMAND="yarn start"
ENV DOCKER_START_COMMAND=${DOCKER_START_COMMAND}

WORKDIR /usr/src/app
USER node
Expand Down
4 changes: 3 additions & 1 deletion images/node/12/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM node:12-alpine

ARG DOCKER_START_COMMAND="yarn watch"

RUN apk add --no-cache --virtual .build-deps \
python \
make \
Expand All @@ -13,7 +15,7 @@ RUN apk add --no-cache --virtual .build-deps \
&& chown node:node /usr/src/app

ENV GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
ENV DOCKER_START_COMMAND="yarn start"
ENV DOCKER_START_COMMAND=${DOCKER_START_COMMAND}

WORKDIR /usr/src/app
USER node
Expand Down
6 changes: 5 additions & 1 deletion internal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func CheckFileExists(file string) bool {
log.Debugln("Checking if file exist:", file)

if file == "" {
log.Debug("Path is empty")
log.Debug("Path is empty.")

return false
}
Expand All @@ -408,7 +408,11 @@ func CheckFileExists(file string) bool {
exist := false

if _, err := AFS.Stat(filePath); !os.IsNotExist(err) {
log.Debugln("File exist:", file)

exist = true
} else {
log.Debugln("File does not exist:", file)
}

return exist
Expand Down
1 change: 1 addition & 0 deletions internal/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ REDIS_PORT=6379
MAIL_DRIVER=sendmail
`, strings.ToUpper(AppName)),
"pwa-studio": `NODE_VERSION=10
`,
"symfony": fmt.Sprintf(`%[1]v_DB=1
%[1]v_REDIS=1
Expand Down
68 changes: 52 additions & 16 deletions internal/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,58 @@ func AppendTemplatesFromPaths(t *template.Template, templateList *list.List, pat
funcs["isEnabled"] = isEnabled

for _, path := range paths {
templatePath := filepath.Join(path)
if CheckFileExists(templatePath) {
log.Traceln("appending template:", templatePath)
templatePath := path
filePath := filepath.Join(GetCwd(), path)

// Check for template in CWD
if CheckFileExists(filePath) {
log.Traceln("appending template from $CWD:", templatePath)

searchT := t.Lookup(templatePath)
if searchT != nil {
log.Traceln("template already defined:", templatePath)
continue
}

child, err := template.New(templatePath).Funcs(sprig.TxtFuncMap()).Funcs(funcs).ParseFiles(templatePath)
child, err := template.New(templatePath).Funcs(sprig.TxtFuncMap()).Funcs(funcs).ParseFiles(filePath)
if err != nil {
return err
}

_, err = t.AddParseTree(child.Name(), child.Tree)
_, err = t.AddParseTree(child.Name(), child.Lookup(filepath.Base(filePath)).Tree)
if err != nil {
return err
}

templateList.PushBack(child.Name())
} else {
log.Traceln("template not found in $CWD:", templatePath)
}

// Check for template in home
filePath = filepath.Join(GetAppHomeDir(), templatePath)
if CheckFileExists(filePath) {
log.Traceln("appending template from app home:", templatePath)

searchT := t.Lookup(templatePath)
if searchT != nil {
log.Traceln("template was already defined:", templatePath)
continue
}

child, err := template.New(templatePath).Funcs(sprig.TxtFuncMap()).Funcs(funcs).ParseFiles(filePath)
if err != nil {
return err
}

_, err = t.AddParseTree(child.Name(), child.Lookup(filepath.Base(filePath)).Tree)
if err != nil {
return err
}

templateList.PushBack(child.Name())
} else {
log.Traceln("template not found:", templatePath)
log.Traceln("template not found in app home:", templatePath)
}
}

Expand All @@ -65,13 +94,21 @@ func AppendTemplatesFromPathsStatic(t *template.Template, templateList *list.Lis

log.Traceln(paths)

for _, v := range paths {
content, err := Asset(v)
for _, path := range paths {
templatePath := filepath.Join(path)

searchT := t.Lookup(templatePath)
if searchT != nil {
log.Traceln("template already defined:", templatePath)
continue
}

content, err := Asset(templatePath)
if err != nil {
log.Traceln(err)
} else {
log.Traceln("appending template:", v)
child, err := template.New(v).Funcs(sprig.TxtFuncMap()).Funcs(funcs).Parse(string(content))
log.Traceln("appending template:", templatePath)
child, err := template.New(templatePath).Funcs(sprig.TxtFuncMap()).Funcs(funcs).Parse(string(content))
if err != nil {
return err
}
Expand All @@ -88,7 +125,6 @@ func AppendTemplatesFromPathsStatic(t *template.Template, templateList *list.Lis

func AppendEnvironmentTemplates(t *template.Template, templateList *list.List, partialName string) error {
envType := GetEnvType()
appHomeDir := viper.GetString("app_dir")
staticTemplatePaths := []string{
filepath.Join("templates", "environments", "includes", fmt.Sprintf("%v.base.yml", partialName)),
filepath.Join("templates", "environments", "includes", fmt.Sprintf("%v.%v.yml", partialName, runtime.GOOS)),
Expand All @@ -97,12 +133,12 @@ func AppendEnvironmentTemplates(t *template.Template, templateList *list.List, p
}
templatePaths := []string{
filepath.Join(
appHomeDir, "templates", "environments", "includes", fmt.Sprintf("%v.base.yml", partialName)),
"templates", "environments", "includes", fmt.Sprintf("%v.base.yml", partialName)),
filepath.Join(
appHomeDir, "templates", "environments", "includes", fmt.Sprintf("%v.%v.yml", partialName, runtime.GOOS)),
"templates", "environments", "includes", fmt.Sprintf("%v.%v.yml", partialName, runtime.GOOS)),
filepath.Join(
appHomeDir, "templates", "environments", envType, fmt.Sprintf("%v.base.yml", partialName)),
filepath.Join(appHomeDir, "templates", "environments", envType, fmt.Sprintf("%v.%v.yml", partialName, runtime.GOOS)),
"templates", "environments", envType, fmt.Sprintf("%v.base.yml", partialName)),
filepath.Join("templates", "environments", envType, fmt.Sprintf("%v.%v.yml", partialName, runtime.GOOS)),
}

log.Traceln("template paths:")
Expand Down Expand Up @@ -183,8 +219,8 @@ func ExecuteTemplate(t *template.Template, buffer io.Writer) error {
funcs["isEnabled"] = isEnabled

log.Debugln("Executing template:", t.Name())

log.Debugln(viper.AllSettings())
log.Debugln(t.DefinedTemplates())

err := t.Funcs(sprig.TxtFuncMap()).Funcs(funcs).ExecuteTemplate(buffer, t.Name(), viper.AllSettings())

Expand Down

0 comments on commit fd76561

Please sign in to comment.