Skip to content

Commit

Permalink
Merge branch 'dev/docker' into dev/dockers
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybatch committed Nov 17, 2023
2 parents 742c6be + f22ae34 commit 1ac5d73
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 5 deletions.
30 changes: 30 additions & 0 deletions .docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash -x

# Do I have a UID in the container
echo "Current user: $CURRENT_UID"
if [ -z "$CURRENT_UID" ]; then
CURRENT_UID=33
fi

# shellcheck disable=SC2153
GROUP_NAME=$(id -gn "$CURRENT_UID")
# shellcheck disable=SC2181
if [ -z "$GROUP_NAME" ]; then
CURRENT_GID=33
GROUP_NAME=www-data
else
CURRENT_GID=$(id -g "$CURRENT_UID")
fi

# Do I have a UID in the container
USER_NAME=$(id -un "${CURRENT_UID}")
if [ -z "$USER_NAME" ]; then
echo arcuser:x:${CURRENT_UID}:${CURRENT_GID}::/var/www:/usr/sbin/nologin >> /etc/passwd
USER_NAME=arcuser
pwconv
fi

echo "Setting permission to $USER_NAME:$GROUP_NAME"
chown -R "${USER_NAME}" /opt/project
umask 0002
su -c "yarn run cross-env NODE_ENV=development API_BASE=${API_BASE} webpack-dev-server --mode development --open" -s /bin/bash "$USER_NAME"
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dockerfile
59 changes: 59 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Docker

If you know what you are doing then jump straight to [components](#components) or [configuration](#configuration) sections, otherwise these instruction should get you started.

1. [Install docker desktop](#install-docker-desktop)

## Install docker desktop

Docker containers are available for Windows, Mac and Linux. Install intructions are here: [docker-composer](https://docs.docker.com/compose/install/). This guide will assume you have followed [Scenario one: Install Docker Desktop](https://docs.docker.com/compose/install/#scenario-one-install-docker-desktop).

## Start the container

Assuming you have a terminal open and have changed directory to the root of this repo:

```bash
docker compose up --build
```

The container will be ready to use when you see output something like this:

```
...
runtime modules 26.6 KiB 12 modules
orphan modules 723 bytes [orphan] 2 modules
javascript modules 1.07 MiB
modules by path ./src/ 207 KiB
modules by path ./src/components/*.vue 46.3 KiB 51 modules
modules by path ./src/pages/*.vue 46.4 KiB 35 modules
modules by path ./src/*.vue 69.8 KiB 8 modules
modules by path ./src/*.js 17.7 KiB 4 modules
modules by path ./src/mixins/*.js 1.74 KiB 4 modules
modules by path ./src/services/*.js 24.9 KiB 2 modules
modules by path ./src/fonts/*.ttf 208 bytes 2 modules
+ 1 module
modules by path ./node_modules/ 882 KiB 92 modules
./fixtures/fixtures.js 7.42 KiB [built] [code generated]
./package.json 1.81 KiB [built] [code generated]
webpack 5.77.0 compiled successfully in 3315 ms
```

If you are using Mac, Linux or WSL you can set the server to run as your user, this means that the files written by the project will be owned by you.

```bash
CURRENT_UID=$(id -u) docker compose up --build
```

Logs will appear in the terminal standard out.

## Wiring it up to ARCVService

This ARCMarket can be wired up to the ARCVService. Just checkout and start ARCVService, then checkout and start ARCVMarket.

```bash
git clone [email protected]:neontribe/ARCVService.git
CURRENT_UID=$(id -u) docker compose -f ARCVService/docker-compose.yml up --build -d
git clone [email protected]:neontribe/ARCVMarket.git
CURRENT_UID=$(id -u) docker compose -f ARCVMarket/docker-compose.yml up --build -d

```
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ FROM base as dev
ENTRYPOINT yarn run dev

FROM base as prod
ENTRYPOINT yarn prod
ENV CURRENT_UID 1000
ENTRYPOINT /opt/project/.docker/docker-entrypoint.sh

21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See Docker.md for more info...
# docker compose run -u $(id -u):$(id -g) arcmarket

version: '2.1'
services:

arcmarket:
build:
context: .
image: neontribe/arcmarket:dev
environment:
API_BASE: "http://arcv-store.test:8000/api"
CURRENT_UID: ${CURRENT_UID}
ports:
- "${ARC_PORT:-8081}:8081"
volumes:
- .:/opt/project
# tty: true
# stdin_open: true
# entrypoint: bash
restart: always
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (location.hostname.match(/localhost|(\.(dev|test))$/)) {
console.log("apiBase", apiBase);
console.log("useMocks", useMocks);
}

console.log("config.js " + apiBase);
export default {
apiBase: apiBase,
env: env,
Expand Down
7 changes: 4 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,15 @@ module.exports = {

if (process.env.NODE_ENV === "development") {
module.exports.mode = "development";
module.exports.devServer.allowedHosts = "all";
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
VERSION: JSON.stringify(gitRevisionPlugin.version()),
COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()),
BRANCH: JSON.stringify(gitRevisionPlugin.branch()),
BUILDDATE: JSON.stringify(now),
"process.env": {
NODE_ENV: "\"development\"",
NODE_ENV: '"development"',
API_BASE: JSON.stringify(API_BASE),
USE_MOCKS: JSON.stringify(USE_MOCKS)
}
Expand All @@ -203,8 +204,8 @@ if (process.env.NODE_ENV === "production") {
BRANCH: JSON.stringify(gitRevisionPlugin.branch()),
BUILDDATE: JSON.stringify(now),
"process.env": {
NODE_ENV: "\"production\""
}
NODE_ENV: '"production"',
},
}),
new CopyWebpackPlugin({
patterns: [
Expand Down

0 comments on commit 1ac5d73

Please sign in to comment.