Skip to content

Commit

Permalink
Merge pull request #210 from getAlby/fix/embed-react
Browse files Browse the repository at this point in the history
feat: embed react dist in go executable
  • Loading branch information
rolznz authored Jan 12, 2024
2 parents 273a744 + 79dd880 commit 86e5ef1
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 81 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
frontend/node_modules
frontend/dist
40 changes: 20 additions & 20 deletions .github/workflows/multiplatform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ jobs:
IMAGENAME: ${{ github.event.repository.name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Check out code
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.20.x
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests
run: go test
- name: Docker build
uses: mr-smithers-excellent/docker-build-push@v6
id: build
with:
image: ${{ env.IMAGENAME }}
registry: ${{ env.REGISTRY }}
multiPlatform: true
platform: linux/amd64,linux/arm64,linux/386
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
name: Check out code
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.20.x
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests
run: mkdir frontend/dist && touch frontend/dist/tmp && go test
- name: Docker build
uses: mr-smithers-excellent/docker-build-push@v6
id: build
with:
image: ${{ env.IMAGENAME }}
registry: ${{ env.REGISTRY }}
multiPlatform: true
platform: linux/amd64,linux/arm64
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
104 changes: 52 additions & 52 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,55 @@ jobs:
IMAGENAME: ${{ github.event.repository.name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Check out code
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.20.x
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests
run: go test
- name: Docker build
uses: mr-smithers-excellent/docker-build-push@v6
id: build
with:
image: ${{ env.IMAGENAME }}
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout deployment repo
uses: actions/checkout@v2
with:
repository: getalby/alby-deployment
path: infrastructure
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
# Always update dev environment
- name: Update dev environment
if: ${{ github.ref == 'refs/heads/main' }}
uses: fjogeleit/[email protected]
with:
valueFile: 'alby-simnet-deployment/values.yaml'
propertyPath: 'nwc.image.tag'
value: ${{ steps.build.outputs.tags }}
repository: getalby/alby-deployment
branch: main
createPR: false
message: 'CD: Update nwc tag to ${{ steps.build.outputs.tags }}'
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
workDir: infrastructure
# Only update prod environment if this action was triggered by a new tag
- name: Update production environment
if: startsWith(github.ref, 'refs/tags')
uses: fjogeleit/[email protected]
with:
valueFile: 'alby-mainnet-deployment/values.yaml'
propertyPath: 'nwc.image.tag'
value: ${{ steps.build.outputs.tags }}
repository: getalby/alby-deployment
branch: main
createPR: false
message: 'CD: Update nwc tag to ${{ steps.build.outputs.tags }}'
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
workDir: infrastructure
- uses: actions/checkout@v2
name: Check out code
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.20.x
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests
run: mkdir frontend/dist && touch frontend/dist/tmp && go test
- name: Docker build
uses: mr-smithers-excellent/docker-build-push@v6
id: build
with:
image: ${{ env.IMAGENAME }}
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout deployment repo
uses: actions/checkout@v2
with:
repository: getalby/alby-deployment
path: infrastructure
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
# Always update dev environment
- name: Update dev environment
if: ${{ github.ref == 'refs/heads/main' }}
uses: fjogeleit/[email protected]
with:
valueFile: "alby-simnet-deployment/values.yaml"
propertyPath: "nwc.image.tag"
value: ${{ steps.build.outputs.tags }}
repository: getalby/alby-deployment
branch: main
createPR: false
message: "CD: Update nwc tag to ${{ steps.build.outputs.tags }}"
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
workDir: infrastructure
# Only update prod environment if this action was triggered by a new tag
- name: Update production environment
if: startsWith(github.ref, 'refs/tags')
uses: fjogeleit/[email protected]
with:
valueFile: "alby-mainnet-deployment/values.yaml"
propertyPath: "nwc.image.tag"
value: ${{ steps.build.outputs.tags }}
repository: getalby/alby-deployment
branch: main
createPR: false
message: "CD: Update nwc tag to ${{ steps.build.outputs.tags }}"
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
workDir: infrastructure
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
FROM node:18-alpine as frontend
WORKDIR /build
COPY frontend ./frontend
RUN cd frontend && yarn install && yarn build

FROM golang:1.20-alpine as builder

# Move to working directory /build
Expand All @@ -11,7 +16,8 @@ RUN go mod download
# Copy the code into the container
COPY . .

# TODO: build react app?
# Copy frontend dist files into the container
COPY --from=frontend /build/frontend/dist ./frontend/dist

# Build the application
RUN go build -o main
Expand All @@ -21,8 +27,5 @@ FROM alpine as final

# Copy the binaries and entrypoint from the builder image.
COPY --from=builder /build/main /bin/
# NOTE: should not be needed - assets should be embedded in the go app
#COPY --from=builder /build/public /public/
#COPY --from=builder /build/views /views/

ENTRYPOINT [ "/bin/main" ]
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ Go to `/frontend`

Follow standard LND instructions. After logging in, you will be redirected to the wrong port (8080), so manually re-open <http://localhost:5173>.

### Build and run locally

`mkdir tmp`
`go build -o main`
`cp main tmp`
`cp .env tmp`
`cd tmp`
`./main`

### Run dockerfile locally

`docker build . -t nwc-local`

`docker run --env-file .env -p 8080:8080 nwc-local`

### Testing

`go test`
Expand Down Expand Up @@ -148,6 +163,7 @@ You can also contribute to our [bounty program](https://github.com/getAlby/light
`get_balance`

`pay_invoice`

- ⚠️ amount not supported (for amountless invoices)

`pay_keysend`
Expand Down Expand Up @@ -178,6 +194,7 @@ You can also contribute to our [bounty program](https://github.com/getAlby/light
`get_balance`

`pay_invoice`

- ⚠️ amount not supported (for amountless invoices)

`pay_keysend`
Expand All @@ -201,3 +218,10 @@ You can also contribute to our [bounty program](https://github.com/getAlby/light
`multi_pay_invoice`

`multi_pay_keysend (TBC)`

## Node Distributions

Run NWC on your own node!

- [https://github.com/getAlby/umbrel-community-app-store](Umbrel)
- [https://github.com/horologger/nostr-wallet-connect-startos](Start9) (WIP)
13 changes: 8 additions & 5 deletions frontend/frontend.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package frontend

import (
"embed"
"net/http"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)

//go:embed dist
var embeddedReactAssets embed.FS

func RegisterHandlers(e *echo.Echo) {
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
Skipper: nil,
// Root directory from where the static content is served.
Root: "frontend/dist",
// Index file for serving a directory.
// Optional. Default value "index.html".
Index: "index.html",
Root: "dist",
// Enable HTML5 mode by forwarding all not-found requests to root so that
// SPA (single-page application) can handle the routing.
HTML5: true,
Browse: false,
IgnoreBase: false,
Filesystem: nil,
Filesystem: http.FS(embeddedReactAssets),
}))
}

0 comments on commit 86e5ef1

Please sign in to comment.