Skip to content

Commit

Permalink
Deploy new ten gateway frontend (#1686)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkokelj authored Dec 11, 2023
1 parent 2fa6089 commit b2ddee0
Show file tree
Hide file tree
Showing 25 changed files with 46 additions and 1,458 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/manual-deploy-obscuro-gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

- name: Build and Push Docker Image
run: |
DOCKER_BUILDKIT=1 docker build -t ${{ vars.DOCKER_BUILD_TAG_GATEWAY }} -f ./tools/walletextension/Dockerfile .
DOCKER_BUILDKIT=1 docker build --build-arg TESTNET_TYPE=${{ github.event.inputs.testnet_type }} -t ${{ vars.DOCKER_BUILD_TAG_GATEWAY }} -f ./tools/walletextension/Dockerfile .
docker push ${{ vars.DOCKER_BUILD_TAG_GATEWAY }}
# This will fail some deletions due to resource dependencies ( ie. you must first delete the vm before deleting the disk)
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ docs/_site
# db files
tools/walletextension/main/.obscuro

# static files generated by npm run build
tools/walletextension/api/static

# contracts

# Logs
Expand Down
22 changes: 21 additions & 1 deletion tools/walletextension/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ FROM golang:1.20-alpine3.18 as system
# set the base libs to build / run
RUN apk add build-base bash git
ENV CGO_ENABLED=1
ARG TESTNET_TYPE

# Standard build stage that initializes the go dependencies
FROM system as get-dependencies
# create the base directory
# setup container data structure
RUN mkdir -p /home/obscuro/go-obscuro


# Install Node.js and npm (needed for frontend)
RUN apk add --update nodejs npm

# Ensures container layer caching when dependencies are not changed
WORKDIR /home/obscuro/go-obscuro
COPY go.mod .
Expand All @@ -27,7 +32,22 @@ FROM get-dependencies as build-wallet
# make sure the geth network code is available
COPY . /home/obscuro/go-obscuro

# build the contract deployer exec
# Create .env file for frontend
WORKDIR /home/obscuro/go-obscuro/tools/walletextension/frontend
RUN if [ "$TESTNET_TYPE" = "dev-testnet" ]; then \
echo "NEXT_PUBLIC_API_GATEWAY_URL=https://dev-testnet.obscu.ro" > .env; \
elif [ "$TESTNET_TYPE" = "uat-testnet" ]; then \
echo "NEXT_PUBLIC_API_GATEWAY_URL=https://uat-testnet.obscu.ro" > .env; \
elif [ "$TESTNET_TYPE" = "sepolia-testnet" ]; then \
echo "NEXT_PUBLIC_API_GATEWAY_URL=https://testnet.obscu.ro" > .env; \
else \
echo "NEXT_PUBLIC_API_GATEWAY_URL=http://127.0.0.1:3000" > .env; \
fi
# Run npm build for frontend
RUN npm install
RUN npm run build

# build the gateway executable
WORKDIR /home/obscuro/go-obscuro/tools/walletextension/main
RUN --mount=type=cache,target=/root/.cache/go-build \
go build -o ../bin/wallet_extension_linux
Expand Down
5 changes: 4 additions & 1 deletion tools/walletextension/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# 👛 The Ten wallet extension
# The Ten gateway

See the documentation [here](https://docs.obscu.ro/wallet-extension/wallet-extension/).

## Developer notes

Running gateway frontend locally requires building static files first.
To do that, run `npm run build` in `tools/walletextension/frontend` folder.

The precompiled binaries for macOS ARM64, macOS AMD64, Windows AMD64 and Linux AMD64 can be built by running the
following commands from the `tools/walletextension/main` folder:

Expand Down
14 changes: 3 additions & 11 deletions tools/walletextension/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import (
"github.com/ten-protocol/go-ten/tools/walletextension/common"
)

//go:embed static
//go:embed staticOG
//go:embed all:static
var staticFiles embed.FS

const (
staticDir = "static"
staticDirOG = "staticOG"
staticDir = "static"
)

// Server is a wrapper for the http server
Expand Down Expand Up @@ -67,13 +65,7 @@ func createHTTPServer(address string, routes []Route) *http.Server {
if err != nil {
panic(fmt.Sprintf("could not serve static files. Cause: %s", err))
}
serveMux.Handle(common.PathViewingKeys, http.StripPrefix(common.PathViewingKeys, http.FileServer(http.FS(noPrefixStaticFiles))))

noPrefixStaticFilesOG, err := fs.Sub(staticFiles, staticDirOG)
if err != nil {
panic(fmt.Errorf("could not serve static files. Cause: %w", err).Error())
}
serveMux.Handle(common.PathObscuroGateway, http.StripPrefix(common.PathObscuroGateway, http.FileServer(http.FS(noPrefixStaticFilesOG))))
serveMux.Handle(common.PathObscuroGateway, http.StripPrefix(common.PathObscuroGateway, http.FileServer(http.FS(noPrefixStaticFiles))))

// Creates the actual http server with a ReadHeaderTimeout to avoid Potential Slowloris Attack
server := &http.Server{Addr: address, Handler: serveMux, ReadHeaderTimeout: common.ReaderHeadTimeout}
Expand Down
Empty file.
21 changes: 0 additions & 21 deletions tools/walletextension/api/static/index.html

This file was deleted.

77 changes: 0 additions & 77 deletions tools/walletextension/api/static/javascript.js

This file was deleted.

34 changes: 0 additions & 34 deletions tools/walletextension/api/static/style.css

This file was deleted.

Binary file removed tools/walletextension/api/staticOG/MetaMaskIcon.png
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion tools/walletextension/api/staticOG/check.svg

This file was deleted.

3 changes: 0 additions & 3 deletions tools/walletextension/api/staticOG/copy.svg

This file was deleted.

Binary file removed tools/walletextension/api/staticOG/favicon-32x32.png
Binary file not shown.
132 changes: 0 additions & 132 deletions tools/walletextension/api/staticOG/index.html

This file was deleted.

Loading

0 comments on commit b2ddee0

Please sign in to comment.