Is there a right way to change a non umbrella project to use umbrella feature with Phoenix framework? - phoenix-framework

Using Phoenix framework now. At the beginning, we didn't use --umbrella option to generate the project. So the structure is like a simple app of umbrella way.
Now want to change the project to the umbrella way. Is it possible and how to do?

As of phoenix 1.3 and elixir 1.5:
Generate a fresh umbrella app in a separate directory:
$ mix new my_umbrella --umbrella
Move your phoenix application to the apps/ directory in the new umbrella directory:
$ mv /path/to/my_app /path/to/my_umbrella/apps/
Your build path, deps folder, and main config and mix files now live in the root of the umbrella. You'll need to add the following lines to your project function in your phoenix mix.exs to point to the right locations as below:
# my_umbrella/apps/my_app/mix.exs
def project do
[
# ...
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
# ...
]
end
Refetch your dependencies from the root of the umbrella.
$ mix deps.get
Assuming you're using brunch, you'll also need to edit the assets/package.json file in your phoenix app folder to point to the correct location for deps/:
// my_umbrella/apps/my_app/assets/package.json
"phoenix": "file:../../../deps/phoenix",
"phoenix_html": "file:../../../deps/phoenix_html"
You may need to refresh the package-lock.json file to re-run npm install command if using a recent version of npm.
From the root of the umbrella, you should be able to start your phoenix server.
$ mix phx.server

Related

heroku: Deploying angular app inside spring boot app

I've one repo sunixi and it has two projects sun-angular(angular) and sun-admin(spring boot) in ts-admin i'm building ts-angular via executions and moving dist into resources/static of sun-admin project after that i'm building the sun-admin. On local enviroment it is working fine but how can i do same in heroku deployment.
structure of repo
sunixi
---sun-angular
---sun-admin
in sun-admin i'm setting workingDirectory as ../sun-angular but while deploying to heroku i'm getting
Cannot run program "npm" (in directory "/tmp/build_02607c07/sun-angular"): error=2, No such file or directory
If you are using a monorepository strategy, an option is to use subdir buildpack to select where is the path of your folder: https://github.com/timanovsky/subdir-heroku-buildpack
If you want to deploy backend and frontend in the same heroku app, the project folder should contains a npm package. Otherwise, i will not work.

Bundling NuxtJS dist directory using go:embed

I have a web app using a NuxtJS frontend being served from a Golang web micro-service.
I am using go:embed dist to ship the frontend assets into the web binary and running it all in a Docker container. For non-Gophers, go:embed is a directive that bundles files or directories into the Go binary. It's a compile error to use go:embed on a directory that doesn't exist.
Usually, you don't commit the dist directory to VCS, but if I don't, then all my CI builds fail because I cannot compile the web service since dist doesn't exist.
I tried adding a .gitignore inside the dist folder like this:
*
!.gitigore
I was hoping this would commit the empty dist folder to VCS, but still not commit any of the assets. This worked fine, until I ran the NuxtJS build and it deleted the .gitignore. I assume it deletes the whole directory and recreates it.
Does anybody know whether there is a configuration option to keep the dist folder around between builds, or at least to not delete the .gitignore within it?

Beego: Routing issues with modules

Routing doesn't work at all for me in bee if I use modules while GOPATH old approach works perfectly.
I am new in golang, correct me if I did something wrong.
I have been trying to create API project with bee, but I found that all new projects have to use the modules approach released in go 1.11.
I used bee api api-name command to scaffold the new project. It appeared in GOPATH. I moved out it from GOPATH path to another directory. Then I did go mod init mod, then I was able to run bee run and API was successfully started but routing didn't work. I did some comparing and found out that commentsRouter file wasn't generated.
What am I do wrong?
I tried to do set GO111MODULE=on and then go get -u github.com/beego/bee but this wasn't helped as well.
Now I can't even run bee API, I see
0004 Failed to build the application: main.go:4:2: package api-name/routers is not in GOROOT (c:\go\src\api-name\routers)
What's happens? I am confused. Official go documentation says that I should prefer modules approach with new projects but I can't find somewhere in docs anything about how to scaffold and use bee with modules system.
Just because missing file commentsRouter_controllers.go. Don't know how beego does not generate file routers/commentsRouter_controllers.go when running app outside $gopath.
Then we can only access to localhost/swagger. Any another path (or route) is all 404 returned.
Solution:
Not a good way but worked:
copy source code of $your_project to $gopath/src
cd $gopath/src/$your_project > bee run (just for generating file commentsRouter_controllers.go) > stop running app
copy file $gopath/src/$your_project/routers/commentsRouter_controllers.go to $your_project/routers
cd $your_project > bee run
Good luck
It looks like latest Beego Bee supports generating routes outside the GOPATH.
Have a check. It did work for me now.

Where do you keep your client source and how do you build it into your application?

Consider the backend-for-frontend pattern. You're using an SPA client like Angular or React which requires a build process and the client depends on your server for content/authentication.
How do you do it?
Is my current folder structure suitable?
go.mod
/bin
# output builds into here here
/httpd
main.go
/handlers
index_get.go
ping_any.go
/platform
# misc packages go here

Gitlab CI - Auto DevOps job failed, Unable to select a buildpack for a Go project?

My Gitlab CI Auto DevOps job failed with
Status: Downloaded newer image for gliderlabs/herokuish:latest
-----> Unable to select a buildpack
ERROR: Job failed: exit code 1
I've gone through
Auto DevOps and
Getting started with Auto DevOps
and am still not sure where I should put the buildpack.
Mine should be heroku-buildpack-go, which I've lost track where I get that from.
My repo consist only a single-character README.md, and the "Hello, playground" main.go.
Conclusion:
Thanks to David's comprehensive explanation, I was able to get DevOps started with correct buildpack:
From this I would conclude that your single .go file at the root of the directory tree does not meet the activation criteria for auto-building Go projects. I'd suggest picking one of the dependency managers in the requirements above and modifying your project to support it.
FTA, I just did touch go.mod then git add & git push and the AutoDevops started building my GO project indeed.
However it seems to me that Gitlab AutoDevops is not able to build any GO projects very easily, as I get the following error (with project variable TRACE=true):
...
!! The go.mod file for this project does not specify a Go version
!!
!! Defaulting to go1.11.1
!!
!! For more details see: https://devcenter.heroku.com/articles/go-apps-with-modules#build-configuration
!!
-----> Installing go1.11.1
-----> Fetching go1.11.1.linux-amd64.tar.gz... done
!! Installing package '.' (default)
!!
!! To install a different package spec add a comment in the following form to your `go.mod` file:
!! // +heroku install ./cmd/...
!!
!! For more details see: https://devcenter.heroku.com/articles/go-apps-with-modules#build-configuration
!!
-----> Running: go install -v -tags heroku .
go: cannot determine module path for source directory /tmp/build (outside GOPATH, no import comments)
ERROR: Job failed: exit code 1
The easier solution is to use .gitlab-ci.yml file instead, documented in
https://blog.boatswain.io/post/build-go-project-with-gitlab-ci/
(and followed up at Gitlab CI - Start Shared Runner for normal repos).
From the AutoDevops documentation:
Auto Build creates a build of the application in one of two ways:
If there is a Dockerfile, it will use docker build to create a Docker image.
Otherwise, it will use Herokuish and Heroku buildpacks to automatically detect and build the application into a Docker image.
Then looking at the build activation criteria, as per the Heroku Go buildpack documentation:
This buildpack will detect your repository as Go if you are using either:
go modules
dep
govendor
glide
GB
Godep
Or more specifically for godep, govendor or GB:
The Heroku Go buildpack is used when an application meets one of the following requirements:
has a Godeps/Godeps.json file, identifying the application as being managed by godep;
has a vendor/vendor.json file, identifying the application as being managed by govendor;
has a src directory, which has sub directories, contains one or more .go files, identifying the application as being managed by gb.
From this I would conclude that your single .go file at the root of the directory tree does not meet the activation criteria for auto-building Go projects. I'd suggest picking one of the dependency managers in the requirements above and modifying your project to support it. After that AutoDevops should start building your project.
If you are still having issues after that, this debugging note might help:
After making sure that the project meets the buildpack requirements;
if it still fails, setting a project variable TRACE=true will enable verbose logging which​ may help to continue troubleshooting.

Resources