Skip to content

Commit

Permalink
refactor: change to workspaces structure
Browse files Browse the repository at this point in the history
This enables separation between server and client dependencies, which
makes it easy to know what is used where.

It also reduces the footprint of the final Docker image, as we only need
the dev deps when building the client bundle, so in the final image we
can include only the server runtime deps.
  • Loading branch information
varl committed Feb 27, 2020
1 parent 58b3bd0 commit 61e9a19
Show file tree
Hide file tree
Showing 189 changed files with 12,454 additions and 20,157 deletions.
5 changes: 5 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
> 0.5%
last 2 versions
Firefox ESR
not ie 11
not dead
17 changes: 13 additions & 4 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
version: 1

update_configs:
- package_manager: "javascript"
directory: "/"
update_schedule: "live"
version_requirement_updates: "increase_versions"
- package_manager: 'javascript'
directory: '/'
update_schedule: 'daily'
version_requirement_updates: 'increase_versions'
target_branch: 'master'
automerged_updates:
- match:
dependency_name: '@dhis2/*'
dependency_type: 'all'
update_type: 'semver:minor'
- match:
dependency_type: 'all'
update_type: 'security:patch'
199 changes: 103 additions & 96 deletions .github/workflows/dockerpush.yml
Original file line number Diff line number Diff line change
@@ -1,103 +1,110 @@
name: 'DHIS2: Docker'

on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master
push:
# Publish `master` as Docker `latest` image.
branches:
- master

# Publish `v1.2.3` tags as releases.
tags:
- v*

# Run tests for any PRs.
pull_request:
# Publish `v1.2.3` tags as releases.
tags:
- v*

# Run tests for any PRs.
pull_request:

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
build-docker:
runs-on: ubuntu-latest

if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- name: Test that dockerfile builds
run: docker build .

test:
runs-on: ubuntu-latest

container:
image: node:lts-slim

services:
postgres:
image: dhis2/postgres-contrib
env:
POSTGRES_USER: apphub
POSTGRES_PASSWORD: apphub
POSTGRES_DB: apphub
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- name: Install deps for tests
run: npm install
- name: Build frontend/client
run: npm run build
- name: Run tests
run: npm run test
env:
RDS_HOSTNAME: postgres
RDS_USERNAME: apphub
RDS_PASSWORD: apphub
RDS_DB_NAME: apphub
RDS_DB_PORT: 5432
AUTH_STRATEGY: jwt
AUTH0_M2M_SECRET: ${{ secrets.AUTH0_M2M_SECRET }}
AUTH0_SECRET: ${{ secrets.AUTH0_SECRET }}
AUTH0_AUDIENCE: ${{ secrets.AUTH0_AUDIENCE }}
AUTH0_DOMAIN: https://dhis2.eu.auth0.com/
AUTH0_ALG: HS256

push:
# Ensure test job passes before pushing image.
needs: [test, build-docker]

runs-on: ubuntu-latest

if: github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip ci]')
steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file Dockerfile --tag image

- name: Log into DockerHub registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin

- name: Push image
run: |
IMAGE_ID=dhis2/app-hub
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
build-docker:
runs-on: ubuntu-latest

if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- name: Test that dockerfile builds
run: docker build .

test:
runs-on: ubuntu-latest

container:
image: node:lts-slim

services:
postgres:
image: dhis2/postgres-contrib
env:
POSTGRES_USER: apphub
POSTGRES_PASSWORD: apphub
POSTGRES_DB: apphub
ports:
- 5432/tcp
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2

- name: Install deps for tests
run: yarn install --frozen-lockfile

- name: Build frontend/client
run: yarn build

- name: Run client tests
run: yarn test:client

- name: Run server tests
run: yarn test:server
env:
RDS_HOSTNAME: postgres
RDS_USERNAME: apphub
RDS_PASSWORD: apphub
RDS_DB_NAME: apphub
RDS_DB_PORT: ${{ job.services.postgres.ports[5432] }}
AUTH_STRATEGY: jwt
AUTH0_M2M_SECRET: ${{ secrets.AUTH0_M2M_SECRET }}
AUTH0_SECRET: ${{ secrets.AUTH0_SECRET }}
AUTH0_AUDIENCE: ${{ secrets.AUTH0_AUDIENCE }}
AUTH0_DOMAIN: https://dhis2.eu.auth0.com/
AUTH0_ALG: HS256

push:
# Ensure test job passes before pushing image.
needs: [test, build-docker]

runs-on: ubuntu-latest

if: github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip ci]')
steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file Dockerfile --tag image

- name: Log into DockerHub registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin

- name: Push image
run: |
IMAGE_ID=dhis2/app-hub
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bundle.zip
.elasticbeanstalk
node_modules/
static/
build/

# ignore all env files, except the template
.env*
Expand Down
12 changes: 10 additions & 2 deletions .huskyrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
const { config } = require('@dhis2/cli-style')
const husky = require(config.husky)

const tasks = arr => arr.join(' && ')

module.exports = {
hooks: {
'commit-msg': 'd2-style commit check',
'pre-commit': 'd2-style validate',
...husky.hooks,
'pre-commit': tasks([
'd2-style js check --staged',
'd2-style text check --staged',
]),
},
}
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ WORKDIR /src

COPY . .

RUN npm install
RUN npm run build
RUN npm pack
RUN yarn install --frozen-lockfile
RUN yarn workspace client build
RUN yarn workspace client pack --filename app-hub-client.tgz

RUN tar zxvf dhis2-app-hub-*.tgz
RUN tar zxvf client/app-hub-client.tgz --directory server/
RUN mv server/package/build server/static && rm -rf server/package

FROM node:lts-slim

Expand All @@ -20,10 +21,10 @@ ENV HOST=0.0.0.0

WORKDIR /srv

COPY --from=build /src/package ./app-hub
COPY --from=build /src/server ./app-hub

WORKDIR app-hub
RUN npm install
RUN yarn install --frozen-lockfile

EXPOSE 3000
CMD ["node", "src/main.js"]
8 changes: 4 additions & 4 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ env:
phases:
install:
runtime-versions:
nodejs: 10
nodejs: 12

pre_build:
commands:
- echo Installing NPM dependencies
- npm install
- echo Installing dependencies
- yarn install

build:
commands:
- echo Entered build phase
- npm run build
- yarn build

post_build:
commands:
Expand Down
5 changes: 5 additions & 0 deletions client/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { config } = require('@dhis2/cli-style')

module.exports = {
extends: [config.eslintReact],
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 61e9a19

Please sign in to comment.