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

Deploy new ten gateway frontend #1686

Merged
merged 5 commits into from
Dec 11, 2023
Merged
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
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-alpine 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 \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if-else block is pretty gross but not a priority haha.

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
Comment on lines +36 to +45
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .env file creation based on TESTNET_TYPE is well-implemented. Ensure that this approach is scalable if additional environment variables are needed in the future.

# Run npm build for frontend
RUN npm install
RUN npm run build
Comment on lines +47 to +48
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using npm ci instead of npm install for more reliable dependency installation when building the application in CI/CD environments.

- RUN npm install
+ RUN npm ci

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
RUN npm install
RUN npm run build
RUN npm ci
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))))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The static files are now served at the common.PathObscuroGateway path, which should align with the updated frontend paths for the gateway backend URLs. Ensure that common.PathObscuroGateway is correctly defined and that the frontend expects assets to be served from this path.


The verification script did not find a definition for common.PathObscuroGateway, which is critical for serving static files at the updated path. Please ensure this variable is correctly defined and accessible where needed.

  • common.PathObscuroGateway appears to be undefined, which is necessary for the updated static file serving path in server.go. Please define this variable or confirm its existence and scope.


// 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
Loading