diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy-test.yml similarity index 76% rename from .github/workflows/deploy.yml rename to .github/workflows/deploy-test.yml index 4446fa95..2c6aec4f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy-test.yml @@ -1,4 +1,4 @@ -name: deploy +name: Deploy Test Environment on: workflow_dispatch @@ -6,11 +6,11 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: wshihadeh/docker-deployment-action@v2 with: remote_docker_host: webstrom@server.strom.sk ssh_private_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PRIVATE_KEY }} ssh_public_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PUBLIC_KEY }} - stack_file_name: compose.yaml + stack_file_name: deployment/compose-test.yaml args: up --build --force-recreate --detach diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 177af80a..c48a9a92 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out branch code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Node.js with Yarn cache uses: actions/setup-node@v3 with: diff --git a/.vscode/settings.json b/.vscode/settings.json index 902d7b93..9a1b58f9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,9 @@ "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" }, + "files.associations": { + "compose-*.yaml": "dockercompose" + }, "git.branchProtection": [ "master" ], diff --git a/compose.yaml b/compose.yaml deleted file mode 100644 index 9f8451e7..00000000 --- a/compose.yaml +++ /dev/null @@ -1,8 +0,0 @@ -version: "3" - -services: - frontend: - build: . - image: webstrom-frontend - network_mode: "host" - restart: always diff --git a/Dockerfile b/deployment/Dockerfile similarity index 64% rename from Dockerfile rename to deployment/Dockerfile index 94f00da7..29846121 100644 --- a/Dockerfile +++ b/deployment/Dockerfile @@ -1,8 +1,10 @@ -FROM node:18 +FROM node:20 + +ARG NEXT_PUBLIC_BE_PORT WORKDIR /app -COPY . ./ +COPY . /app RUN yarn && yarn build diff --git a/deployment/compose-test.yaml b/deployment/compose-test.yaml new file mode 100644 index 00000000..d099232e --- /dev/null +++ b/deployment/compose-test.yaml @@ -0,0 +1,19 @@ +version: "3" + +services: + webstrom-frontend: + build: + dockerfile: deployment/Dockerfile + context: .. + args: + - NEXT_PUBLIC_BE_PORT=8920 + + image: webstrom-test-frontend + + environment: + - PORT=8922 + - NEXT_PUBLIC_BE_PORT=8920 + + network_mode: host + + restart: always diff --git a/deployment/local-mac/Dockerfile b/deployment/local-mac/Dockerfile new file mode 100644 index 00000000..f077a757 --- /dev/null +++ b/deployment/local-mac/Dockerfile @@ -0,0 +1,13 @@ +FROM node:20 + +ARG NEXT_PUBLIC_BE_PORT +ARG NEXT_PUBLIC_BE_HOSTNAME + +WORKDIR /app + +COPY . /app + +RUN yarn && yarn build + +ENTRYPOINT [ "yarn", "start", "-H", "0.0.0.0" ] + diff --git a/deployment/local-mac/README.md b/deployment/local-mac/README.md new file mode 100644 index 00000000..67d48dc5 --- /dev/null +++ b/deployment/local-mac/README.md @@ -0,0 +1,30 @@ +# Ako pustit Docker na macOS + +## Co pustam + +- `docker-compose -f deployment/local-mac/compose.yaml up --build --force-recreate` + - da sa prihodit aj `--detach` ked chceme pustit v backgrounde (bez neho vidime server logy priamo v terminali) + +Treba mat samozrejme Docker a docker-compose atd. + +## Urobene zmeny oproti compose-test + +Ked som chcel pustit Docker na macu, musel som urobil nasledujuce zmeny (poradilo ChatGPT): + +### `compose.yml` + +- zmenil som aj meno suboru (lebo nebuildime "test" environment a.k.a test.strom.sk) +- vymena `network_mode: host` za `ports: - '3000:3000'` - network_mode vraj na macu nefunguje +- pridanie `- NEXT_PUBLIC_BE_HOSTNAME=host.docker.internal` - aby sa to vedelo pripojit na lokalny BE - Docker pouziva takyto hostname pre host machine localhost +- zmenil som porty na 3000/8000 ako standardne pouzivame pre development +- `dockerfile` a `context` cesty podla file struktury novych suborov + +### `Dockerfile` + +- host v `ENTRYPOINT`e na `"0.0.0.0"` + - od ChatGPT: You're trying to start the application with `yarn start -H localhost`. This command might not be correctly binding to all network interfaces. Usually, you'd use `-H 0.0.0.0` to ensure the app listens on all interfaces, including those available within a Docker container. (a naozaj to pomohlo, inak mi stranku browser nenacital) +- pridany `ARG NEXT_PUBLIC_BE_HOSTNAME` pre nacitanie env varu z compose + +### BE `settings.py` + +- `ALLOWED_HOSTS = ['host.docker.internal']` - BE krical, ze treba :shrug: diff --git a/deployment/local-mac/compose.yaml b/deployment/local-mac/compose.yaml new file mode 100644 index 00000000..d65dbe24 --- /dev/null +++ b/deployment/local-mac/compose.yaml @@ -0,0 +1,20 @@ +services: + webstrom-frontend: + build: + dockerfile: deployment/local-mac/Dockerfile + context: ../.. + args: + - NEXT_PUBLIC_BE_PORT=8000 + - NEXT_PUBLIC_BE_HOSTNAME=host.docker.internal + + image: webstrom-test-frontend + + environment: + - PORT=3000 + - NEXT_PUBLIC_BE_PORT=8000 + - NEXT_PUBLIC_BE_HOSTNAME=host.docker.internal + + ports: + - '3000:3000' + + restart: always