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

opa-react-demo: switch to prod mode build for demo #8

Merged
merged 1 commit into from
Jul 18, 2024
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
7 changes: 3 additions & 4 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ jobs:
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version: 22
- name: setup and build
# https://github.com/npm/cli/issues/3034#issuecomment-885211061
- name: build and start
run: |
npm ci
npm run build
docker compose up --build -d
docker compose down
working-directory: ${{ matrix.pkg }}
1 change: 1 addition & 0 deletions opa-react-demo/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
12 changes: 12 additions & 0 deletions opa-react-demo/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
:4000 {
handle_path /eopa/* {
reverse_proxy http://eopa:8181
}

# serve the react app
handle {
root * /usr/share/caddy
try_files {path} /
file_server
}
}
16 changes: 6 additions & 10 deletions opa-react-demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
FROM node:22
FROM node:22 AS builder

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install

# Bundle app source
COPY . /usr/src/app
RUN npm ci
RUN npm run build

EXPOSE 3000
CMD [ "npm", "start" ]
FROM caddy:latest
COPY --from=builder /usr/src/app/build /usr/share/caddy
COPY Caddyfile /etc/caddy/Caddyfile
2 changes: 1 addition & 1 deletion opa-react-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This React application showcases the request batching feature of `@styra/opa-rea

1. Set `$EOPA_LICENSE_KEY`
1. Run `docker compose up`
1. Go to <http://127.0.0.1:3000>
1. Go to <http://127.0.0.1:4000>

### Binaries

Expand Down
13 changes: 3 additions & 10 deletions opa-react-demo/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
services:
react-demo:
build: .
expose:
- 3000
ports:
- "4000:4000"
depends_on:
- eopa
command:
- npm
- start
network_mode: host

eopa:
image: ghcr.io/styrainc/enterprise-opa:latest
expose:
- 8181
ports:
- "8181:8181"
command:
Expand All @@ -22,8 +16,7 @@ services:
- --addr=:8181
- --log-level=debug
- /policies
working_dir: /
volumes:
- ./policies:/policies
environment:
EOPA_LICENSE_KEY: ${EOPA_LICENSE_KEY}
EOPA_LICENSE_KEY: ${EOPA_LICENSE_KEY}
9 changes: 4 additions & 5 deletions opa-react-demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion opa-react-demo/src/BatchDemo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function BatchDemo() {
const [opaClient] = useState(() => {
const href = window.location.toString();
const u = new URL(href); // TODO(sr): better way?!
u.pathname = "";
u.pathname = "eopa";
u.search = "";
return new OPAClient(u.toString());
});
Expand Down