Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/1.1.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccallister committed Oct 6, 2020
2 parents 68ac31e + 1481c32 commit da233d8
Show file tree
Hide file tree
Showing 50 changed files with 1,568 additions and 188 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ composer.lock
/coverage.txt
/production-site
nitro.exe
*.sql
/*.sql
/*.sql.gz
*.env*
/nitrod
/docs
/docs
/cmd/test
*.sql.zip
49 changes: 34 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,52 @@
# Release Notes for Craft Nitro

### 1.0.1 - 2020-08-12
## 1.1.0 - 2020-10-06

## Changed
### Added
- Added the `nitro create` command, which will set up a new Craft installation without PHP or Composer installed locally. ([#101](https://github.com/craftcms/nitro/issues/101))
- Added the `--silent` flag to the `xon`, `xoff`, and `php iniset` commands.

### Changed
- The `db import` command can now import zip and gzip files.
- The `db import` command will now detect the database backup type and automatically select the appropriate database engine, if the backup file was uncompressed. ([#132](https://github.com/craftcms/nitro/issues/132))
- The `db import` and `db add` commands now replaces dashes (`-`) with underscores (`_`) in the specified database name, to workaround a SQL error. ([#212](https://github.com/craftcms/nitro/issues/212))
- The `php iniset` command can now set the `display_errors` config setting. ([#172](https://github.com/craftcms/nitro/issues/172))
- The `display_errors` config setting is now set to `On` by default.

### Fixed
- Fixed a bug where `php iniset memory_limit` was listed as an available command.
- Fixed a bug where `php iniset` commands weren’t always setting the correct values. ([#207](https://github.com/craftcms/nitro/issues/207))
- Fixed a bug where `php iniget` commands weren’t always returning the correct values.
- Fixed a bug where the system’s `hosts` file wasn’t getting updated on Linux machines. ([#213](https://github.com/craftcms/nitro/issues/213))

## 1.0.1 - 2020-08-12

### Changed
- Composer is now installed by default on new machines.
- The default Nginx site is now a friendly landing page with helpful links.

## Fixed
### Fixed
- Fixed an error that occurred when checking for the latest version of Nitro. ([#199](https://github.com/craftcms/nitro/issues/199))

### 1.0.0 - 2020-08-11
## 1.0.0 - 2020-08-11

## Added
### Added
- Added the `support` command to quickly create GitHub issues pre-populated with environment info.

## Changed
### Changed
- The `info` command now displays additional info such as IP, PHP version, and links to common tasks.

## Fixed
### Fixed
- Fixed a bug confirmation prompts would take just about any input as a “yes”. ([#190](https://github.com/craftcms/nitro/issues/190))

### 1.0.0-RC1.1 - 2020-08-07
## 1.0.0-RC1.1 - 2020-08-07

## Fixed
### Fixed
- Fixed an issue that occurred when creating new machines.

### 1.0.0-RC1 - 2020-08-07
## 1.0.0-RC1 - 2020-08-07

## Added
### Added
- Added the `nginx start`, `nginx stop`, and `nginx restart` commands.
- Added the `php start`, `php stop`, and `php restart` commands. ([#57](https://github.com/craftcms/nitro/issues/57))
- Added the `php iniget` command, which can be used to see current php.ini values.
Expand All @@ -39,16 +58,16 @@
### Changed
Improved Composer performance when run from inside the virtual machine. ([#186](https://github.com/craftcms/nitro/issues/186))

## Fixed
### Fixed
- Fixed a bug where the default PHP version was not getting updated when running the `apply` command. ([#192](https://github.com/craftcms/nitro/issues/192))
- Fixed command completion when pressing the <kbd>Tab</kbd> key.

### 1.0.0-beta.10 - 2020-06-04
## 1.0.0-beta.10 - 2020-06-04

## Added
### Added
- Added support for a `NITRO_EDIT_HOSTS` environment variable so that when set to `false`, Nitro will never edit the host machine’s `hosts` file.

## Changed
### Changed
- The `destroy` command now has a `--skip-hosts` option.

## 1.0.0-beta.9 - 2020-06-02
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: install scripts

VERSION ?= 1.0.1
VERSION ?= 1.1.0
NITRO_DEFAULT_MACHINE ?= nitro-dev

build:
Expand All @@ -20,6 +20,9 @@ dev: scripts api
test:
go test ./...

vet:
go vet ./...

releaser:
goreleaser --skip-publish --rm-dist --skip-validate

Expand All @@ -45,6 +48,7 @@ setup: build-api
multipass exec ${NITRO_DEFAULT_MACHINE} -- sudo systemctl enable nitrod
proto:
protoc internal/nitrod/nitrod.proto --go_out=plugins=grpc:.

journalctl:
multipass exec ${NITRO_DEFAULT_MACHINE} -- journalctl -u nitrod -f
scripts:
multipass mount scripts ${NITRO_DEFAULT_MACHINE}:/home/ubuntu/scripts
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module github.com/craftcms/nitro

go 1.14
go 1.15

require (
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/golang/protobuf v1.4.2
github.com/h2non/filetype v1.1.0
github.com/jasonmccallister/hosts v0.0.0-20200601172247-0748f05d919e
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.3.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/h2non/filetype v1.1.0 h1:Or/gjocJrJRNK/Cri/TDEKFjAR+cfG6eK65NGYB6gBA=
github.com/h2non/filetype v1.1.0/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down Expand Up @@ -177,6 +179,7 @@ github.com/pixelandtonic/prompt v1.1.8/go.mod h1:46FVcLYd9TRiHXOLQ6nXzeaYO1Twh8Z
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
12 changes: 12 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"google.golang.org/grpc"

"github.com/craftcms/nitro/internal/nitro"
"github.com/craftcms/nitro/internal/nitrod"
)

Expand All @@ -20,6 +21,17 @@ func NewClient(ip, port string) (nitrod.NitroServiceClient, error) {
return nitrod.NewNitroServiceClient(cc), nil
}

func NewDefaultClient(machine string) (nitrod.NitroServiceClient, error) {
ip := nitro.IP(machine, nitro.NewMultipassRunner("multipass"))

cc, err := grpc.Dial(ip+":"+"50051", grpc.WithInsecure())
if err != nil {
log.Fatal("error creating nitrod client, error:", err)
}

return nitrod.NewNitroServiceClient(cc), nil
}

// NewSystemClient takes the ip address and port and creates
// a new gRPC client for interacting with the nitrod systems
// service.
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ var applyCommand = &cobra.Command{
}
}

if err := runas.Elevated(machine, []string{"hosts"}); err != nil {
if err := runas.Elevated(machine, []string{"hosts", "--config-file", viper.ConfigFileUsed()}); err != nil {
return err
}
}
Expand Down
171 changes: 171 additions & 0 deletions internal/cmd/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package cmd

import (
"archive/zip"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"

"github.com/pixelandtonic/prompt"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/craftcms/nitro/internal/config"
"github.com/craftcms/nitro/internal/helpers"
"github.com/craftcms/nitro/internal/validate"
)

const craftDownloadURL = "https://craftcms.com/latest-v3.zip"

var createcommand = &cobra.Command{
Use: "create",
Short: "Create a project",
RunE: func(cmd *cobra.Command, args []string) error {
_ = flagMachineName
p := prompt.NewPrompt()
// load the config
var configFile config.Config
if err := viper.Unmarshal(&configFile); err != nil {
return err
}

// prompt the user for input
dir, err := p.Ask("What is the name of the project?", &prompt.InputOptions{
AppendQuestionMark: false,
})
if err != nil {
return err
}

// clean up the directory name
dir = strings.TrimSpace(strings.Replace(dir, " ", "-", -1))

// check if the directory exists
if helpers.DirExists(dir) {
return errors.New(fmt.Sprintf("Directory %q already exists", dir))
}

// prompt the user for the sites hostname, default to the directory name
hostname, err := p.Ask("Enter the hostname", &prompt.InputOptions{
Default: dir,
Validator: validate.Hostname,
})
if err != nil {
return err
}

// download craft
file, err := download()
if err != nil {
return err
}

projectPath, err := filepath.Abs(dir)
if err != nil {
return err
}

fmt.Println(fmt.Sprintf("Creating project folder %s...", dir))

// unzip the files
if err := unzip(file, projectPath); err != nil {
return err
}

// apply flags to add command
args = append(args, dir)
add := addCommand
if err := add.Flag("hostname").Value.Set(hostname); err != nil {
return err
}
if err := add.Flag("webroot").Value.Set("web"); err != nil {
return err
}

return add.RunE(cmd, args)
},
}

func download() (*os.File, error) {
r, err := http.Get(craftDownloadURL)
if err != nil {
return nil, err
}
defer r.Body.Close()

// create the temp file
f, err := ioutil.TempFile(os.TempDir(), "nitro-craft-cms-download")
if err != nil {
return nil, err
}
defer f.Close()

fmt.Println("Downloading Craft CMS...")

// copy the downloaded contents into the temp file
_, err = io.Copy(f, r.Body)
if err != nil {
return nil, err
}

return f, nil
}

func unzip(source *os.File, path string) error {
r, err := zip.OpenReader(source.Name())
if err != nil {
return err
}
defer r.Close()

// move files into place
for _, f := range r.File {
path := filepath.Join(path, f.Name)

// zipslip
//if !strings.HasPrefix(path, filepath.Clean(path)+string(os.PathSeparator)) {
// log.Printf("%s: illegal file path", path)
// continue
//}

// create if a directory
if f.FileInfo().IsDir() {
if err := os.MkdirAll(path, os.ModePerm); err != nil {
return err
}
continue
}

// create the files
if err = os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
return err
}

out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
if err != nil {
return err
}

readerCloser, err := f.Open()
if err != nil {
return err
}

_, err = io.Copy(out, readerCloser)

// cleanup
_ = out.Close()
_ = readerCloser.Close()

if err != nil {
return err
}
}

return nil
}
Loading

0 comments on commit da233d8

Please # to comment.