diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7bbf646..78fb752 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -5,10 +5,59 @@ on: branches: [ "master" ] pull_request: branches: [ "master" ] + schedule: + - cron: '0 10 * * 1' # run "At 10:00 on Monday" + +permissions: + contents: read jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: '1.23' + check-latest: true + - name: Run Go Format + run: gofmt -s -w . && git diff --exit-code + - name: Run Go Tidy + run: go mod tidy && git diff --exit-code + - name: Run Go Vet + run: go vet ./... + - name: Run Go Mod + run: go mod download + - name: Run Go Mod Verify + run: go mod verify + - uses: golangci/golangci-lint-action@v6 + with: + version: latest + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + - name: Run tests + run: go test -v -count=1 -race -shuffle=on -coverprofile=coverage.txt ./... + - name: Go Benchmark + run: go test -v -shuffle=on -run=- -bench=. -benchtime=1x ./... + - name: Install govulncheck + run: go install golang.org/x/vuln/cmd/govulncheck@latest + # - name: Run govulncheck + # run: govulncheck -test ./... + # - name: Upload Coverage + # uses: codecov/codecov-action@v3 + # continue-on-error: true # we don't care if it fails + # with: + # token: ${{secrets.CODECOV_TOKEN}} # set in repository settings + # file: ./coverage.txt # file from the previous step + # fail_ci_if_error: false + build: + needs: [test, lint] runs-on: ubuntu-latest strategy: matrix: @@ -20,14 +69,8 @@ jobs: goos: windows steps: - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v4 + - uses: actions/setup-go@v4 with: - go-version: '1.22' - + go-version: '1.23' - name: Build run: GOARCH=${{ matrix.goarch }} GOOS=${{ matrix.goos }} go build -v ./... - - # - name: Test - # run: go test -v ./... diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b2ad4e4..807e08f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -28,3 +28,7 @@ jobs: goos: ${{ matrix.goos }} goarch: ${{ matrix.goarch }} project_path: "./cmd/" + build_flags: -v + ldflags: -X "version.VERSION=${{ github.ref_name }}" + # -X "main.buildTime=${{ env.BUILD_TIME }}" -X main.gitCommit=${{ github.sha }} -X main.gitRef=${{ github.ref }} + extra_files: LICENSE README.md diff --git a/.gitignore b/.gitignore index b4784a4..c9c1cbc 100644 --- a/.gitignore +++ b/.gitignore @@ -187,3 +187,5 @@ build/** *.log tmp core + +tests/convert/.upsun/** diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1c50957 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "convsun Run", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceRoot}/cmd/upsun_convert.go", + "args": [ + "--src=${workspaceRoot}/tests/convert", + "--mount_type=instance" + ] + }, + { + "name": "convsun Help", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceRoot}/cmd/upsun_convert.go", + "args": [ "--help" ] + }, + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 7841e37..ec4dbda 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,18 @@ ConvSun ========= -This tool uses **Platform.sh** config files *(routes.yaml, services.yaml and .platform.app.yaml)* to generate the **Upsun** config file *(config.yaml)* -> **WARNING : This tool handles classic 'multi-app...' cases but has not been tested for snowflack cases.** +This CLI-tool uses **Platform.sh** config files *(routes.yaml, services.yaml and .platform.app.yaml(s)/applications.yaml)* to generate the **Upsun** config file *(config.yaml)* + +> [!CAUTION] +> **This project is owned by the Upsun Advocacy team. It is in early stage of development [experimental] and only intended to be used with caution by Upsun customers/community.

This project is not supported by Upsun and does not qualify for Support plans. Use this repository at your own risks, it is provided without guarantee or warranty!** +> Don’t hesitate to join our [Discord](https://discord.gg/upsun) to share your thoughts about this project. + +> **WARNING: This tool handles classic 'multi-app...' cases but has not been tested for snowflake cases.** + +#### Install + +Download the last binary in [release section](https://github.com/upsun/convsun/releases). +Extract it and enjoy! #### Syntax ``` @@ -14,4 +24,4 @@ Usage of convsun: ``` #### Sample -`$ upsun_convert --src=tests/convert"` \ No newline at end of file +`$ convsun --src=tests/convert"` diff --git a/go.mod b/go.mod index 2dcbec2..9492b92 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module github.com/upsun/convsun -go 1.22.6 +go 1.23.5 require ( github.com/spf13/pflag v1.0.5 - github.com/upsun/lib-sun v0.3.4 + github.com/upsun/lib-sun v0.3.14 ) require ( diff --git a/go.sum b/go.sum index aa62c89..7b0f1c8 100644 --- a/go.sum +++ b/go.sum @@ -16,8 +16,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/upsun/lib-sun v0.3.4 h1:ANSleT49LOUHBO/gdKLzXTquC583K3h6IfKfUcQ2uH8= -github.com/upsun/lib-sun v0.3.4/go.mod h1:8AtRNv0L+c9qCS/maO/OVFIn2VDi89LTkWwpB7YKTDE= +github.com/upsun/lib-sun v0.3.14 h1:qD36j2bPMbGMmDH7Gu8lI8KZtTt+HnmeO/O/kRZ08ec= +github.com/upsun/lib-sun v0.3.14/go.mod h1:8AtRNv0L+c9qCS/maO/OVFIn2VDi89LTkWwpB7YKTDE= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= diff --git a/internal/logic/convert_config.go b/internal/logic/convert_config.go index dbc6dcc..2a34685 100644 --- a/internal/logic/convert_config.go +++ b/internal/logic/convert_config.go @@ -47,6 +47,7 @@ func Convert(projectWorkspace string, outputFilePath string) { // if entry.ValueNode != nil { log.Println("Replace all mount type on " + entity.PSH_PLATFORM + "/" + entity.PSH_APPLICATION + "...") readers.ReplaceAllEntry(&metamodel.Applications, "local", app.ArgsC.TypeMount) + readers.ReplaceAllEntry(&metamodel.Applications, "shared", app.ArgsC.TypeMount) // } // - Remove Disk diff --git a/tests/convert/.platform.app.yaml b/tests/convert/.platform.app.yaml new file mode 100644 index 0000000..0da66d6 --- /dev/null +++ b/tests/convert/.platform.app.yaml @@ -0,0 +1,67 @@ +name: app + +# Runtime pre-install +type: 'php:8.2' + +# Disk for App +disk: 2048 + +# Flexible Ressources +resources: + base_memory: 1024 + memory_ratio: 1024 + +dependencies: + php: + composer/composer: "^2" + +# vHost config +web: + locations: + "/": + root: "public" + passthru: "/index.php" + allow: true + scripts: true + +relationships: + database: "mysql:mysql" + +variables: + env: + CI_ENVIRONMENT: "production" + +# RW fs !! +mounts: + "writable/cache": + source: local + source_path: "writable/cache" + "writable/debugbar": { source: local, source_path: "writable/debugbar"} + "writable/logs": + source: local + source_path: "writable/logs" + "writable/session": + source: local + source_path: "writable/session" + "writable/upload": + source: local + source_path: "writable/upload" + "config": + source: local + source_path: "config" + +# Custom commands +hooks: + build: | + set -e + composer install --no-dev --optimize-autoloader + deploy: | + set -e + php generate_env.php + +source: + operations: + auto-update: + command: | + curl -fsS https://raw.githubusercontent.com/platformsh/source-operations/main/setup.sh | { bash /dev/fd/3 sop-autoupdate; } 3<&0 + diff --git a/tests/convert/.platform/applications.yaml b/tests/convert/.platform/applications.yaml new file mode 100644 index 0000000..e637975 --- /dev/null +++ b/tests/convert/.platform/applications.yaml @@ -0,0 +1,121 @@ +- name: drupal + type: php:8.1 + source: + root: drupal + dependencies: + php: + composer/composer: ^2 + nodejs: + n: "*" + variables: + env: + N_PREFIX: /app/.global + php: + memory_limit: "256M" + runtime: + extensions: + - redis + - newrelic + - apcu + relationships: + database: drupaldb:mysql + databox: drupaldb:databox + redis: cache:redis + auctionssearch: search_solr:auctionssearch + databasesearch: search_solr:databasesearch + userssearch: search_solr:userssearch + orderssearch: search_solr:orderssearch + collectionsearch: search_solr:collectionsearch + disk: 16384 + resources: + base_memory: 1024 + memory_ratio: 1024 + mounts: + web/sites/default/files: + source: local + source_path: files + /tmp: + source: local + source_path: tmp + /private: + source: local + source_path: private + /.drush: + source: local + source_path: drush + /drush-backups: + source: local + source_path: drush-backups + /.console: + source: local + source_path: console + /storage: + source: local + source_path: storage + build: + flavor: none + hooks: + build: | + set -e + n auto + hash -r + composer install --no-dev --prefer-dist --no-progress --no-interaction --optimize-autoloader --apcu-autoloader + composer dumpautoload -o + curl -fsS https://platform.sh/cli/installer | php + deploy: | + set -e + php ./drush/platformsh_generate_drush_yml.php + drush -y updatedb + drush -y config-import + drush -y cache-rebuild + drush locale:check + drush locale:update + web: + locations: + /: + root: web + expires: 1d + passthru: /index.php + allow: false + headers: + Access-Control-Allow-Origin: "*" + rules: + \.(jpe?g|png|gif|svgz?|css|js|map|ico|bmp|eot|woff2?|otf|ttf|webmanifest)$: + allow: true + ^/robots\.txt: + allow: true + ^/sitemap\.xml$: + allow: true + ^/sites/sites\.php$: + scripts: false + ^/sites/[^/]+/settings.*?\.php$: + scripts: false + /sites/default/files: + allow: true + expires: 2w + passthru: /index.php + root: web/sites/default/files + scripts: false + rules: + ^/sites/default/files/(css|js): + expires: 2w + crons: + drupal: + spec: '*/5 * * * *' + cmd: drush core-cron + backup: + spec: '0 5 * * *' + cmd: | + if [ "$PLATFORM_ENVIRONMENT_TYPE" = production ]; then + platform backup:create --yes --no-wait + fi + workers: + queues: + size: S + disk: 1024 + commands: + start: php worker.php +- name: app2 + type: php:8.1 + source: + root: app2 diff --git a/tests/convert/.platform/local/.gitkeep b/tests/convert/.platform/local/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/convert/.platform/routes.yaml b/tests/convert/.platform/routes.yaml new file mode 100644 index 0000000..38b70f0 --- /dev/null +++ b/tests/convert/.platform/routes.yaml @@ -0,0 +1,8 @@ +# This is my default route +“https://{default}/“: + type: upstream + upstream: app:http +# Redirect just... +“http://{default}“: + type: redirect + to: “https://{default}/” \ No newline at end of file diff --git a/tests/convert/.platform/services.yaml b/tests/convert/.platform/services.yaml new file mode 100644 index 0000000..e1aa78f --- /dev/null +++ b/tests/convert/.platform/services.yaml @@ -0,0 +1,35 @@ +sqldb: + # (https://docs.platform.sh/configuration/services/mysql.html#supported-versions) + type: mysql:10.5 + disk: 1024 + size: M + +timedb: + # (https://docs.platform.sh/configuration/services/influxdb.html#supported-versions) + type: influxdb:1.8 + disk: 1024 + +searchelastic: + # (https://docs.platform.sh/configuration/services/elasticsearch.html#supported-versions) + type: elasticsearch:7.10 + size: AUTO + disk: 9216 + resources: + base_memory: 512 + memory_ratio: 512 + +queuerabbit: + # (https://docs.platform.sh/configuration/services/rabbitmq.html#supported-versions) + type: rabbitmq:3.8 + # Canot be down size at 512Mo but consom 500Mo by default => Alerting (but why 512Mo limit ???) + # https://docs.platform.sh/configuration/services/rabbitmq.html#example-configuration + # https://www.rabbitmq.com/quorum-queues.html#resource-use + disk: 1024 + +headlessbrowser: + # (https://docs.platform.sh/configuration/services/headless-chrome.html#supported-versions) + type: chrome-headless:91 + #size: 4XL + resources: + base_memory: 512 + memory_ratio: 512 \ No newline at end of file diff --git a/tests/convert/.platform/solr-config/config.json b/tests/convert/.platform/solr-config/config.json new file mode 100644 index 0000000..e69de29 diff --git a/tests/convert/.upsun/.gitkeep b/tests/convert/.upsun/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/convert/.upsun/config-ref.yaml b/tests/convert/.upsun/config-ref.yaml new file mode 100644 index 0000000..b0367e0 --- /dev/null +++ b/tests/convert/.upsun/config-ref.yaml @@ -0,0 +1,192 @@ +applications: + app: + # Runtime pre-install + type: 'php:8.2' + dependencies: + php: + composer/composer: "^2" + # vHost config + web: + locations: + "/": + root: "public" + passthru: "/index.php" + allow: true + scripts: true + relationships: + database: "mysql:mysql" + variables: + env: + CI_ENVIRONMENT: "production" + # RW fs !! + mounts: + "writable/cache": + source: instance + source_path: "writable/cache" + "writable/debugbar": {source: instance, source_path: "writable/debugbar"} + "writable/logs": + source: instance + source_path: "writable/logs" + "writable/session": + source: instance + source_path: "writable/session" + "writable/upload": + source: instance + source_path: "writable/upload" + "config": + source: instance + source_path: "config" + # Custom commands + hooks: + build: | + set -e + composer install --no-dev --optimize-autoloader + deploy: | + set -e + php generate_env.php + source: + operations: + auto-update: + command: | + curl -fsS https://raw.githubusercontent.com/platformsh/source-operations/main/setup.sh | { bash /dev/fd/3 sop-autoupdate; } 3<&0 + root: / + drupal: + type: php:8.1 + source: + root: drupal + dependencies: + php: + composer/composer: ^2 + nodejs: + n: "*" + variables: + env: + N_PREFIX: /app/.global + php: + memory_limit: "256M" + runtime: + extensions: + - redis + - newrelic + - apcu + relationships: + database: drupaldb:mysql + databox: drupaldb:databox + redis: cache:redis + auctionssearch: search_solr:auctionssearch + databasesearch: search_solr:databasesearch + userssearch: search_solr:userssearch + orderssearch: search_solr:orderssearch + collectionsearch: search_solr:collectionsearch + mounts: + web/sites/default/files: + source: instance + source_path: files + /tmp: + source: instance + source_path: tmp + /private: + source: instance + source_path: private + /.drush: + source: instance + source_path: drush + /drush-backups: + source: instance + source_path: drush-backups + /.console: + source: instance + source_path: console + /storage: + source: instance + source_path: storage + build: + flavor: none + hooks: + build: | + set -e + n auto + hash -r + composer install --no-dev --prefer-dist --no-progress --no-interaction --optimize-autoloader --apcu-autoloader + composer dumpautoload -o + curl -fsS https://platform.sh/cli/installer | php + deploy: | + set -e + php ./drush/platformsh_generate_drush_yml.php + drush -y updatedb + drush -y config-import + drush -y cache-rebuild + drush locale:check + drush locale:update + web: + locations: + /: + root: web + expires: 1d + passthru: /index.php + allow: false + headers: + Access-Control-Allow-Origin: "*" + rules: + \.(jpe?g|png|gif|svgz?|css|js|map|ico|bmp|eot|woff2?|otf|ttf|webmanifest)$: + allow: true + ^/robots\.txt: + allow: true + ^/sitemap\.xml$: + allow: true + ^/sites/sites\.php$: + scripts: false + ^/sites/[^/]+/settings.*?\.php$: + scripts: false + /sites/default/files: + allow: true + expires: 2w + passthru: /index.php + root: web/sites/default/files + scripts: false + rules: + ^/sites/default/files/(css|js): + expires: 2w + crons: + drupal: + spec: '*/5 * * * *' + cmd: drush core-cron + backup: + spec: '0 5 * * *' + cmd: | + if [ "$PLATFORM_ENVIRONMENT_TYPE" = production ]; then + platform backup:create --yes --no-wait + fi + workers: + queues: + commands: + start: php worker.php + app2: + type: php:8.1 + source: + root: app2 +services: + sqldb: + # (https://docs.platform.sh/configuration/services/mysql.html#supported-versions) + type: mysql:10.5 + timedb: + # (https://docs.platform.sh/configuration/services/influxdb.html#supported-versions) + type: influxdb:1.8 + searchelastic: + # (https://docs.platform.sh/configuration/services/elasticsearch.html#supported-versions) + type: elasticsearch:7.10 + queuerabbit: + # (https://docs.platform.sh/configuration/services/rabbitmq.html#supported-versions) + type: rabbitmq:3.8 + headlessbrowser: + # (https://docs.platform.sh/configuration/services/headless-chrome.html#supported-versions) + type: chrome-headless:91 +routes: + # This is my default route + “https://{default}/“: + type: upstream + upstream: app:http + # Redirect just... + “http://{default}“: + type: redirect + to: “https://{default}/”