Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rough in a Bridgetown scanner #3962

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions scanner/bridgetown.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package scanner

import "github.com/pkg/errors"

func configureBridgetown(sourceDir string, _ *ScannerConfig) (*SourceInfo, error) {
if !checksPass(sourceDir, dirContains("Gemfile", "bridgetown")) {
return nil, nil
}

s := &SourceInfo{
Family: "Bridgetown",
Port: 4000,
Statics: []Static{
{
GuestPath: "/app/output",
UrlPrefix: "/",
},
},
}

rubyVersion, err := extractRubyVersion("Gemfile.lock", "Gemfile", ".ruby_version")
if err != nil {
return nil, errors.Wrap(err, "failure extracting Ruby version")
}

vars := make(map[string]interface{})
vars["rubyVersion"] = rubyVersion
s.Files = templatesExecute("templates/bridgetown", vars)

return s, nil
}
39 changes: 22 additions & 17 deletions scanner/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"os/exec"
"regexp"
"strings"

"github.com/pkg/errors"
)

func configureRuby(sourceDir string, config *ScannerConfig) (*SourceInfo, error) {
Expand All @@ -18,23 +20,8 @@ func configureRuby(sourceDir string, config *ScannerConfig) (*SourceInfo, error)
}

rubyVersion, err := extractRubyVersion("Gemfile.lock", "Gemfile", ".ruby_version")

if err != nil || rubyVersion == "" {
rubyVersion = "3.1.2"

out, err := exec.Command("ruby", "-v").Output()
if err == nil {

version := strings.TrimSpace(string(out))
re := regexp.MustCompile(`ruby (?P<version>[\d.]+)`)
m := re.FindStringSubmatch(version)

for i, name := range re.SubexpNames() {
if len(m) > 0 && name == "version" {
rubyVersion = m[i]
}
}
}
if err != nil {
return nil, errors.Wrap(err, "failure extracting Ruby version")
}

vars := make(map[string]interface{})
Expand Down Expand Up @@ -101,5 +88,23 @@ func extractRubyVersion(lockfilePath string, gemfilePath string, rubyVersionPath
}
}

if version == "" {
version = "3.3.5"

out, err := exec.Command("ruby", "-v").Output()
if err == nil {

versionString := strings.TrimSpace(string(out))
re := regexp.MustCompile(`ruby (?P<version>[\d.]+)`)
m := re.FindStringSubmatch(versionString)

for i, name := range re.SubexpNames() {
if len(m) > 0 && name == "version" {
version = m[i]
}
}
}
}

return version, nil
}
1 change: 1 addition & 0 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func Scan(sourceDir string, config *ScannerConfig) (*SourceInfo, error) {
since they might mix languages or have a Dockerfile that
doesn't work with Fly */
configureDockerfile,
configureBridgetown,
configureLucky,
configureRuby,
configureGo,
Expand Down
29 changes: 29 additions & 0 deletions scanner/templates/bridgetown/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ARG RUBY_VERSION={{ .rubyVersion }}
FROM ruby:$RUBY_VERSION-slim as base

ENV VOLTA_HOME=/usr/local

RUN apt-get update &&\
apt-get install --yes build-essential git curl

RUN curl https://get.volta.sh | bash &&\
volta install node@lts yarn@latest

WORKDIR /app

FROM base as gems
COPY Gemfile* .
RUN bundle install

FROM base
COPY . .
COPY --from=base $VOLTA_HOME/bin $VOLTA_HOME/bin
COPY --from=base $VOLTA_HOME/tools $VOLTA_HOME/tools
COPY --from=base /app /app
COPY --from=gems /usr/local/bundle /usr/local/bundle

RUN yarn install
RUN bundle exec bridgetown frontend:build

EXPOSE 4000
CMD bundle exec bridgetown start
Loading