Skip to content

Commit 4b66029

Browse files
Ny struktur og diverse rydding
Dette er en squashed commit pga endel feiling og nye forsøk som forurenser commithistorikken mer enn den forklarer. - flytter applikasjoner inn i pakker - nye alias for import på tvers av applikasjoner - diverse endringer
1 parent 305199f commit 4b66029

File tree

933 files changed

+1918
-1335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

933 files changed

+1918
-1335
lines changed

.eslintrc.json

+15-34
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
{
2-
"plugins": ["css-modules", "no-relative-import-paths"],
3-
"extends": [
4-
"next/core-web-vitals",
5-
"plugin:css-modules/recommended",
6-
"plugin:storybook/recommended"
7-
],
8-
"ignorePatterns": ["next.config.js"],
2+
"plugins": ["css-modules", "@typescript-eslint"],
3+
"extends": [],
94
"rules": {
10-
"@next/next/no-img-element": 0,
115
"css-modules/no-unused-class": [
126
1,
137
{
@@ -20,36 +14,23 @@
2014
"camelCase": true
2115
}
2216
],
23-
"import/order": [
17+
"@typescript-eslint/no-unused-vars": [
2418
"warn",
2519
{
26-
"groups": [
27-
["builtin", "external"],
28-
["internal", "parent", "index", "object", "unknown", "type"],
29-
"sibling"
30-
],
31-
"pathGroups": [
32-
{
33-
"pattern": "./**/*.module.scss",
34-
"group": "sibling",
35-
"position": "after"
36-
}
37-
]
38-
}
39-
],
40-
"no-console": "warn",
41-
"no-alert": "error",
42-
"no-relative-import-paths/no-relative-import-paths": [
43-
"warn",
44-
{
45-
"allowSameFolder": true,
46-
"rootDir": "src"
20+
"varsIgnorePattern": "^_",
21+
"argsIgnorePattern": "^_",
22+
"caughtErrorsIgnorePattern": "^_"
4723
}
4824
]
4925
},
50-
"settings": {
51-
"css-modules": {
52-
"basePath": "src"
26+
"overrides": [
27+
{
28+
"files": ["workspaces/nextjs/**/*.ts", "workspaces/nextjs/**/*.tsx"],
29+
"settings": {
30+
"css-modules": {
31+
"basePath": "workspaces/nextjs/src"
32+
}
33+
}
5334
}
54-
}
35+
]
5536
}
File renamed without changes.
File renamed without changes.

failover/.npmrc .failover/.npmrc

File renamed without changes.

failover/Dockerfile .failover/Dockerfile

+10-7
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ ARG GITHUB_PAT
1212
ARG SERVICE_SECRET
1313
ARG ENV_FILE
1414

15-
COPY package*.json /failover/.npmrc /app/
16-
COPY server /app/server/
15+
COPY package*.json .failover/.npmrc /app/
16+
17+
COPY packages/server /app/packages/server/
18+
COPY packages/nextjs /app/packages/nextjs/
19+
COPY packages/shared /app/packages/shared/
1720

1821
RUN npm ci --ignore-scripts
1922
RUN rm -f .npmrc
2023

21-
COPY public /app/public/
22-
COPY src /app/src/
23-
COPY srcCommon /app/srcCommon/
24-
COPY next.config.js tsconfig.json .eslintrc.json /app/
25-
COPY "/failover/$ENV_FILE" /app/.env
24+
COPY ".failover/${ENV_FILE}" /app/.env
25+
# Also copy this .env file to the nextjs and server packages so they can
26+
# pick the environment variables as needed.
27+
COPY /app/.env /app/packages/nextjs/.env
28+
COPY /app/.env /app/packages/server/.env
2629

2730
RUN npm run build
2831

failover/build-dev-failover-image.sh .failover/build-dev-failover-image.sh

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
# Script for building failover-images for dev-environments
44
# Usage: "build-dev-failover-image.sh <dev1|dev2> <image name>"
5-
# XP service secret should be put in the appropriate file (.secret-dev1|.secret-dev2)
6-
# You also need a Github PAT with repo and packages write access in the .github-token
7-
# file at the root of the project
8-
# Take care not to expose secrets!
5+
#
6+
# About secrets:
7+
# As NPM packages with ie post-install scripts could potentially sniff and compromise secrets,
8+
# we need to read secrets from environment variables. These variables should be set using
9+
# ie. 1Password CLI or similar.
10+
#
11+
# The secrets are: NAV_ENONICXP_DEV1, NAV_ENONICXP_DEV2 AND GITHUB_PAT.
912
#
1013
# Once the image is built, use the relevant deploy action on Github with the chosen
1114
# image name to deploy
@@ -24,20 +27,18 @@ fi
2427
if [[ "$APP_ENV" == "dev1" ]]
2528
then
2629
echo "Building image $IMAGE_NAME for dev1"
27-
SERVICE_SECRET=$(<.secret-dev1)
30+
SERVICE_SECRET=$NAV_ENONICXP_DEV1
2831
ENV_FILE=".env-dev1"
2932
elif [[ "$APP_ENV" == "dev2" ]]
3033
then
3134
echo "Building image $IMAGE_NAME for dev2"
32-
SERVICE_SECRET=$(<.secret-dev2)
35+
SERVICE_SECRET=$NAV_ENONICXP_DEV2
3336
ENV_FILE=".env-dev2"
3437
else
3538
echo "Invalid ENV specified, aborting"
3639
exit
3740
fi
3841

39-
GITHUB_PAT=$(<../.github-token)
40-
4142
IMAGE_NAME_FULL="ghcr.io/navikt/nav-enonicxp-frontend:$IMAGE_NAME"
4243

4344
docker build -f Dockerfile -t "$IMAGE_NAME_FULL" --no-cache --build-arg ENV_FILE="$ENV_FILE" --build-arg SERVICE_SECRET="$SERVICE_SECRET" --build-arg GITHUB_PAT="$GITHUB_PAT" ../.

.failover/testfile.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
testfile

.github/workflows/build-image.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ jobs:
6767
name: Build docker image
6868
runs-on: ubuntu-latest
6969
permissions:
70-
contents: read
71-
id-token: write
70+
contents: 'read'
71+
id-token: 'write'
7272
environment: ${{ inputs.environment }}
7373
outputs:
7474
image: ${{ steps.docker-push.outputs.image }}
@@ -78,7 +78,7 @@ jobs:
7878
- name: Setup node.js
7979
uses: actions/setup-node@v4
8080
with:
81-
node-version: 20
81+
node-version: '20'
8282
registry-url: 'https://npm.pkg.github.com'
8383
cache: 'npm'
8484
- name: Set app environmment
@@ -101,10 +101,12 @@ jobs:
101101
IMAGE_CACHE_DIR=/tmp/images
102102
NEXT_TELEMETRY_DISABLED=1
103103
EOF
104+
- name: Copy env to nextjs and server workspaces
105+
run: cp .env packages/nextjs/.env && cp .env packages/server/.env
104106
- name: Nextjs cache
105107
uses: actions/cache@v4
106108
with:
107-
path: ${{ github.workspace }}/.next/cache
109+
path: ${{ github.workspace }}/packages/nextjs/.next/cache
108110
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}
109111
- name: Install dependencies
110112
run: npm ci
@@ -122,7 +124,7 @@ jobs:
122124
uses: nais/deploy/actions/cdn-upload/v2@master
123125
with:
124126
team: personbruker
125-
source: ./.next/static
127+
source: ./packages/nextjs/.next/static
126128
destination: nav-enonicxp-frontend/_next
127129
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
128130
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}

.gitignore

+29-34
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,55 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

33
# dependencies
4-
/node_modules
5-
/server/node_modules
6-
/.pnp
7-
.pnp.js
4+
**/node_modules
5+
**/.pnp
6+
**/.pnp.js
87

98
# testing
10-
/coverage
11-
*storybook.log
12-
/storybook-static
9+
**/coverage
10+
**/storybook.log
11+
**/storybook-static
1312

1413
# next.js
15-
/.next/
16-
/.next-static/
17-
/out/
18-
19-
# production
20-
/build
14+
**/.next
15+
**/.next-static
16+
**/out
2117

2218
# misc
2319
.DS_Store
2420
*.pem
2521

2622
# debug
27-
npm-debug.log*
28-
yarn-debug.log*
29-
yarn-error.log*
23+
**/npm-debug.log*
24+
**/yarn-debug.log*
25+
**/yarn-error.log*
3026

3127
# vercel
3228
.vercel
3329

3430
# local env
35-
.env
36-
.env.local
37-
.env.development.local
38-
.env.prod-local.local
31+
**/.env
32+
**/.env.local
33+
**/.env.development.local
34+
**/.env.prod-local.local
3935

4036
/.idea/
41-
/nav-enonicxp-frontend.iml
37+
**/nav-enonicxp-frontend.iml
4238

4339
# secrets, careful!
44-
/.github-token
45-
/failover/.secret-dev1
46-
/failover/.secret-dev2
40+
**/.github-token
41+
**/.failover/.secret-dev1
42+
**/.failover/.secret-dev2
4743

48-
/tsconfig.tsbuildinfo
49-
/image-manifest
50-
/benchmark.mjs
44+
**/tsconfig.tsbuildinfo
45+
**/image-manifest
46+
**/benchmark.mjs
5147

52-
/server/.dist/
53-
/server/tsconfig.tsbuildinfo
54-
/server/__test-utils/next-dummy/.next/
48+
**/.dist/
49+
**/tsconfig.tsbuildinfo
50+
**/__test-utils/next-dummy/.next/
5551

5652
# VS Code
57-
.vscode
58-
/.env.prod-local.local
59-
/server/.next/
60-
/analyze/
53+
**/.vscode
54+
**/.env.prod-local.local
55+
**/analyze

.husky/pre-commit

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#!/usr/bin/env sh
2-
. "$(dirname -- "$0")/_/husky.sh"
3-
4-
npx lint-staged
1+
cd packages/nextjs
2+
npx eslint --max-warnings=0 '**/*.{ts,tsx}'
3+
cd ../server
4+
npx eslint --max-warnings=0 '**/*.{ts,tsx}'
5+
cd ../shared
6+
npx eslint --max-warnings=0 '**/*.{ts,tsx}'
7+
cd ../../

.lintstagedrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
'packages/nextjs/**/*.{ts,tsx}': [
3+
'prettier --write',
4+
'npx eslint --debug --config ./packages/nextjs/.eslintrc.json',
5+
],
6+
'packages/nextjs/**/*.{scss,css}': ['prettier --write'],
7+
};

Dockerfile

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ RUN adduser --system --uid 1001 nextjs
55

66
WORKDIR /app
77

8-
COPY package*.json next.config.js .env /app/
9-
COPY .next /app/.next/
10-
COPY public /app/public/
8+
COPY package*.json .env /app/
9+
10+
COPY packages/nextjs/package*.json packages/nextjs/next.config.js .env /app/nextjs/
11+
COPY packages/nextjs/.next /app/nextjs/.next/
12+
COPY packages/nextjs/public /app/nextjs/public/
13+
1114
COPY node_modules /app/node_modules/
1215

13-
COPY /server/package*.json /app/server/
14-
COPY /server/.dist /app/server/.dist/
16+
COPY .env /app/server/
17+
COPY packages/server/package*.json /app/server/
18+
COPY packages/server/.dist /app/server/.dist/
1519

1620
USER nextjs
1721

1822
EXPOSE 3000
19-
CMD ["npm", "start"]
23+
CMD ["npm", "run", "start-in-docker"]

README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ Kjøres lokalt på [http://localhost:3000](http://localhost:3000).
1010

1111
Som default kreves en lokal instans av Enonic XP med [nav-enonicxp](https://github.com/navikt/nav-enonicxp) installert. Alternativt kan en dev eller prod-instans av XP benyttes via [nav-enonicxp-dev-proxy](https://github.com/navikt/nav-enonicxp-dev-proxy).
1212

13+
### VS Code
14+
15+
Hvis lintingreglene i pakkene ikke plukkes opp av VS Code, sørg for å ha følgende innstillinger i .vscode/settings.json:
16+
17+
```
18+
{
19+
"eslint.workingDirectories": ["./packages/nextjs", "./packages/shared", "./packages/server"]
20+
}
21+
```
22+
1323
### Development mode:
1424

1525
#### Med lokal XP:
@@ -66,8 +76,8 @@ og servere denne som en fallback.
6676

6777
Failover deployes ikke automatisk til dev-miljøer. For å bygge og deploye til et dev-miljø, gjør følgende:
6878

69-
- Legg inn relevante secrets lokalt som spesifisert i kommentarer i `/failover/build-dev-failover-image.sh`
70-
- Kjør `/failover/build-dev-failover-image.sh <dev1|dev2> <image-navn>`
79+
- Legg inn relevante secrets lokalt som spesifisert i kommentarer i `.failover/build-dev-failover-image.sh`
80+
- Kjør `./.failover/build-dev-failover-image.sh <dev1|dev2> <image-navn>`
7181
- Vent på at imaget bygges (det tar normalt 15-20 min)
7282
- Kjør Github workflow'en `deploy-failover.dev` med dev-miljøet og image-navnet du valgte som input
7383

0 commit comments

Comments
 (0)