Skip to content

Commit

Permalink
ci: Use heroku for preview (#130)
Browse files Browse the repository at this point in the history
* ci: Use heroku for preview

Signed-off-by: Xuanwo <[email protected]>

* Fix image missing

Signed-off-by: Xuanwo <[email protected]>

* Fix field

Signed-off-by: Xuanwo <[email protected]>

* Fix dockerfile

Signed-off-by: Xuanwo <[email protected]>

* Add comment

Signed-off-by: Xuanwo <[email protected]>

* Install make

Signed-off-by: Xuanwo <[email protected]>

* Add context

Signed-off-by: Xuanwo <[email protected]>

* Fix build

Signed-off-by: Xuanwo <[email protected]>

* Work around go fmt

Signed-off-by: Xuanwo <[email protected]>

* Remove git clean

Signed-off-by: Xuanwo <[email protected]>

* Add dockerignore

Signed-off-by: Xuanwo <[email protected]>

* Use dockerfile cmd instead

Signed-off-by: Xuanwo <[email protected]>

* trigger

* rename to web instead

Signed-off-by: Xuanwo <[email protected]>

* Fix host that used in docker

Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Aug 13, 2021
1 parent 141bcaf commit b83c731
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 10 deletions.
60 changes: 60 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Created by .ignore support plugin (hsz.mobi)
### Go template
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

### IntelliJ user template

# IntelliJ project files
.idea
*.iml
out
gen

db
bin
dist
node_modules

releases

api/ui/*
!api/ui/ui.go

# Flutter/Dart/Pub related
ui/**/doc/api/
ui/**/ios/Flutter/.last_build_id
ui/.dart_tool/
ui/.flutter-plugins
ui/.flutter-plugins-dependencies
ui/.packages
ui/.pub-cache/
ui/.pub/
ui//build/

# Web related
ui/lib/generated_plugin_registrant.dart

# Symbolication related
ui/app.*.symbols

# Obfuscation related
ui/app.*.map.json

# Android Studio will place build artifacts here
ui/android/app/debug
ui/android/app/profile
ui/android/app/release
25 changes: 21 additions & 4 deletions build/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04
FROM ubuntu:20.04 AS builder

ENV UID=1000
ENV GID=1000
Expand All @@ -13,16 +13,17 @@ ENV FLUTTER_URL="https://storage.googleapis.com/flutter_infra/releases/$FLUTTER_
ENV FLUTTER_HOME="/home/$USER/flutter"
ENV FLUTTER_WEB_PORT="8090"
ENV FLUTTER_DEBUG_PORT="42000"
ENV PATH="$GO_ROOT/:$FLUTTER_HOME/bin:$PATH"
ENV PATH="$GO_ROOT/bin:$FLUTTER_HOME/bin:$PATH"

# install all dependencies
ENV DEBIAN_FRONTEND="noninteractive"
RUN apt-get update \
&& apt-get install --yes --no-install-recommends openjdk-$JAVA_VERSION-jdk curl unzip sed git bash xz-utils libglvnd0 ssh xauth x11-xserver-utils libpulse0 libxcomposite1 libgl1-mesa-glx \
&& apt-get install --yes --no-install-recommends build-essential openjdk-$JAVA_VERSION-jdk curl unzip sed git bash xz-utils libglvnd0 ssh xauth x11-xserver-utils libpulse0 libxcomposite1 libgl1-mesa-glx libprotoc-dev\
&& rm -rf /var/lib/{apt,dpkg,cache,log}

# go
RUN curl -sSL -o go.tar.gz $GO_URL \
&& rm -rf /usr/local/go \
&& tar -C /usr/local -xzf go.tar.gz

# create user
Expand All @@ -37,4 +38,20 @@ RUN curl -sSL -o flutter.tar.xz $FLUTTER_URL \
&& mkdir -p $FLUTTER_HOME \
&& tar xf flutter.tar.xz -C /home/$USER \
&& rm flutter.tar.xz \
&& flutter config --no-analytics
&& flutter config --no-analytics

# Add build context into container
ADD --chown=1000:1000 . /home/$USER

# Build beyond-tp
RUN make build

FROM ubuntu:20.04
ENV UID=1000
ENV GID=1000
ENV USER="developer"
WORKDIR /home/$USER
COPY --from=builder /home/$USER/bin/beyondtp ./

ENV PORT=7436
CMD ./beyondtp server --db db --host 0.0.0.0 --port $PORT --rpc-port 7000
20 changes: 14 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SHELL := /bin/bash
GO_BUILD_OPTION := -trimpath -tags netgo
GO_BUILD_OPTION := -trimpath

.PHONY: check format vet lint build test

Expand Down Expand Up @@ -31,14 +31,22 @@ vet:

build-frontend:
@echo "build frontend"
@git clean -Xf api/ui/
cd ./ui && flutter build web --release
@cp -r ui/build/web/* api/ui
cp -r ui/build/web/* api/ui
@echo "ok"

build: tidy check build-frontend
# We remove check target to work around build failed in container build.
# If we build in container, we will meet errors like:
#
# > go fmt
# > go: not formatting packages in dependency modules
# > package github.com/google/flatbuffers/grpc/tests: C++ source files not allowed when not using cgo or SWIG: grpctest.cpp message_builder_test.cpp
# > package github.com/google/flatbuffers/samples: C++ source files not allowed when not using cgo or SWIG: sample_bfbs.cpp sample_binary.cpp sample_text.cpp
# > package github.com/google/flatbuffers/tests: C++ source files not allowed when not using cgo or SWIG: monster_test.grpc.fb.cc native_type_test_impl.cpp test.cpp test_assert.cpp test_builder.cpp
# > make: *** [Makefile:19: format] Error 1
build: tidy build-frontend
@echo "build beyondtp"
go build ${GO_BUILD_OPTION} -race -o ./bin/beyondtp ./cmd/beyondtp
CGO_ENABLED=1 go build ${GO_BUILD_OPTION} -race -o ./bin/beyondtp ./cmd/beyondtp
@echo "ok"

release: generate tidy check build-frontend
Expand Down Expand Up @@ -71,4 +79,4 @@ tidy:
@echo "Tidy and check the go mod files"
@go mod tidy
@go mod verify
@echo "Done"
@echo "Done"
3 changes: 3 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"stack": "container"
}
3 changes: 3 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
docker:
web: Dockerfile

0 comments on commit b83c731

Please sign in to comment.