Skip to content

Commit 55c13f8

Browse files
Use devcontainers for AvaTax app (#1729)
1 parent 3199295 commit 55c13f8

File tree

8 files changed

+100
-56
lines changed

8 files changed

+100
-56
lines changed

.devcontainer/avatax/Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM mcr.microsoft.com/devcontainers/typescript-node:22
2+
3+
ENV PNPM_HOME="/home/node/.pnpm"
4+
ENV PATH="$PNPM_HOME:$PATH"
5+
RUN corepack enable
6+
7+
WORKDIR /app
8+
9+
# This is needed so pnpm-store volume is created with correct permissions (see docker-compose.yml)
10+
RUN mkdir -p /app/.pnpm-store
11+
RUN chown -R node:node /app/.pnpm-store
12+
13+
RUN pnpm install --frozen-lockfile --filter=app-avatax
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "AvaTax app",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "avatax",
5+
"workspaceFolder": "/app/apps/avatax",
6+
"forwardPorts": [3000, "dynamodb:8000"],
7+
"portsAttributes": {
8+
"3000": {
9+
"label": "AvaTax app"
10+
},
11+
"dynamodb:8000": {
12+
"label": "Local DynamoDB"
13+
}
14+
},
15+
"postCreateCommand": "./scripts/setup-dynamodb.sh",
16+
"features": {
17+
"ghcr.io/devcontainers/features/aws-cli": {}
18+
}
19+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
services:
2+
avatax:
3+
image: avatax
4+
command: sleep infinity # keeps docker container running
5+
build:
6+
context: ../..
7+
dockerfile: .devcontainer/avatax/Dockerfile
8+
volumes:
9+
- "../..:/app"
10+
- "pnpm-store:/app/.pnpm-store"
11+
12+
dynamodb:
13+
image: "amazon/dynamodb-local:latest"
14+
ports:
15+
- 8000:8000
16+
volumes:
17+
- "dynamodb-data:/home/dynamodblocal/data"
18+
command: "-jar DynamoDBLocal.jar -sharedDb -dbPath /home/dynamodblocal/data"
19+
user: root # needed to write to volume
20+
21+
volumes:
22+
dynamodb-data:
23+
driver: local
24+
pnpm-store:
25+
driver: local

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
node_modules
55
.pnp
66
.pnp.js
7+
.pnpm-store
78

89
# testing
910
coverage

Dockerfile.avatax.dev

-18
This file was deleted.

apps/avatax/README.md

+31-22
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,51 @@
1818
<a href="https://twitter.com/getsaleor">🐦 Twitter</a>
1919
</div>
2020

21-
## Documentation
21+
## Running app locally in development containers
22+
23+
The easiest way of running Saleor for local development is to use [development containers](https://containers.dev/).
24+
If you have Visual Studio Code follow their [guide](https://code.visualstudio.com/docs/devcontainers/containers#_quick-start-open-an-existing-folder-in-a-container) on how to open existing folder in container.
25+
26+
Development container only creates container, you still need to start the server. See [common-commands](#common-commands) section to learn more.
27+
28+
Development container will have two ports opened:
29+
30+
1. `3000` - were AvaTax app dev server will listen to requests
31+
2. `8000` - were local DynamoDB will listen to requests and allow [NoSQL Workbench for DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/workbench.html) to connect
32+
33+
### Common commands
34+
35+
Running app in development server:
36+
37+
```shell
38+
pnpm run dev
39+
```
40+
41+
Running tests:
2242

23-
Visit [AvaTax App documentation](https://docs.saleor.io/docs/3.x/developer/app-store/apps/avatax/overview) to learn how to configure and develop the app locally.
43+
```shell
44+
pnpm run test
45+
```
2446

25-
### DynamoDB
47+
## DynamoDB
2648

27-
DynamoDB is used to store Client-side logs. To develop this feature locally:
49+
DynamoDB is used to store Client-side logs. To develop this feature locally use development containers or use [docker-compose](../../.devcontainer/avatax/docker-compose.yml) from `.devcontainer`:
2850

2951
1. Run `docker compose up` for local DynamoDB instance
30-
2. Run `bash scripts/setup-dynamodb.sh` to describe DynamoDB table
52+
2. Run `./scripts/setup-dynamodb.sh` to describe DynamoDB table
3153

3254
Ensure following env variables are set
3355

3456
```dotenv
35-
FF_ENABLE_EXPERIMENTAL_LOGS=true
3657
DYNAMODB_LOGS_ITEM_TTL_IN_DAYS=30
3758
DYNAMODB_LOGS_TABLE_NAME=avatax-client-logs # must match scripts/setup-dynamodb.sh
3859
```
3960

4061
Alternatively, you can connect to AWS-based DynamoDB:
4162

42-
1. Create table in your AWS, based on parameters in `scripts/setup-dynamodb.sh`
63+
1. Create table in your AWS, based on parameters in [`scripts/setup-dynamodb.sh`](./scripts/setup-dynamodb.sh)
4364
2. Set AWS-specific [env variables](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-environment.html)
4465

45-
If `FF_ENABLE_EXPERIMENTAL_LOGS` is not set, you don't have to provide anything - feature will be disabled
46-
4766
## Testing
4867

4968
### E2E tests
@@ -119,7 +138,7 @@ PROMO_CODE=
119138

120139
The app has an example environment for `localhost` in `environments/localhost.bru`. You can copy it to bootstrap your own environment e.g `cloud.bru` (which will be ignored by git).
121140

122-
### Webhook migration scripts
141+
## Webhook migration scripts
123142

124143
> [!NOTE]
125144
> This section refers to apps hosted by Saleor or using REST APL. If you self host AvaTax app you need to write your own logic for updating migration scripts.
@@ -139,16 +158,6 @@ To start the migration run command:
139158
pnpm migrate
140159
```
141160

142-
### Running the app in docker
143-
144-
To run the app in docker, you need to build the image first (run this command in the root directory of the monorepo):
145-
146-
```shell
147-
docker build --tag saleor-app-avatax-docker --file Dockerfile.avatax.dev .
148-
```
149-
150-
Then you can run the image (run this command in the root directory of the monorepo):
161+
## Documentation
151162

152-
```shell
153-
docker run -p 3000:3000 --env-file apps/avatax/.env saleor-app-avatax-docker
154-
```
163+
Visit [AvaTax App documentation](https://docs.saleor.io/docs/3.x/developer/app-store/apps/avatax/overview) to learn how to configure the app.

apps/avatax/docker-compose.yaml

-12
This file was deleted.

apps/avatax/scripts/setup-dynamodb.sh

100644100755
+11-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
#!/bin/bash
2-
if ! aws dynamodb describe-table --table-name avatax-client-logs --endpoint-url http://localhost:8000 --region localhost >/dev/null 2>&1; then
3-
aws dynamodb create-table --table-name avatax-client-logs \
2+
set -e
3+
4+
# needed for aws-cli to work with local dynamodb
5+
aws configure set aws_access_key_id test
6+
aws configure set aws_secret_access_key test
7+
aws configure set region localhost
8+
9+
if ! aws dynamodb describe-table --table-name avatax-logs --endpoint-url http://dynamodb:8000 --region localhost >/dev/null 2>&1; then
10+
aws dynamodb create-table --table-name avatax-logs \
411
--attribute-definitions AttributeName=PK,AttributeType=S AttributeName=SK,AttributeType=S \
512
--key-schema AttributeName=PK,KeyType=HASH AttributeName=SK,KeyType=RANGE \
613
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
7-
--endpoint-url http://localhost:8000 \
14+
--endpoint-url http://dynamodb:8000 \
815
--region localhost
916
else
10-
echo "Table avatax-client-logs already exists - creation is skipped"
17+
echo "Table avatax-logs already exists - creation is skipped"
1118
fi

0 commit comments

Comments
 (0)