Skip to content

Commit

Permalink
Improve newcomer onboarding january 2023 (hobbyfarm#146)
Browse files Browse the repository at this point in the history
* Improve CONTRIBUTING.md

* Merge gitignore entried in root gitignore file

* Fix README.md

* Update package-lock.json to lockfileVersion 2

* Remove warning in tsconfig.json file

* Cosmetic code changes (remove / add empty lines)

* Merge CONTRIBUTING file in README and remove run with docker-compose

* Fix typo in README

* Remove useless nginx.conf

* Rename cicd folder in .docker

* Remove useless .env.example

* Split GitHub actions in CI & PKG pipelines

* Add badges in README

* Fix badges

* Fix English typo

* Update README

* Update README
  • Loading branch information
devpro authored Feb 6, 2023
1 parent b584b72 commit d475483
Show file tree
Hide file tree
Showing 15 changed files with 16,483 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ server {
listen 80 default_server;
server_name _;
root /usr/share/nginx/html;

index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
# This will allow you to refresh page in your angular app. Which will not give error 404.
}

}
File renamed without changes.
9 changes: 0 additions & 9 deletions .env.example

This file was deleted.

4 changes: 2 additions & 2 deletions cicd/Dockerfile → .github/workflows/Dockerfile-ci
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Should only be used with GitHub Actions cicd
# Should only be used with GitHub Actions CI pipeline
# For local, refer to Dockerfile at root of project

FROM nginx:stable-alpine

COPY dist/* /usr/share/nginx/html

# copy staged files
COPY cicd/stage-release/ /
COPY .docker/stage-release/ /

ENTRYPOINT ["entrypoint.sh"]
47 changes: 47 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Continuous Integration (Packaging) pipeline

name: CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch: {}

concurrency:
group: "ci"
cancel-in-progress: true

env:
app_image: hobbyfarm/admin-ui

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master

- name: Setup node_modules cache
id: cache-nodemodules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# cache node_modules to improve performance dramatically
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Install dependencies
run: npm install

- name: Build
run: npm run build:prod

# TODO: lint, sonar, tests

- name: Create container image
run: |
docker build -f .github/workflows/Dockerfile-ci -t hobbyfarm/admin-ui:${GIT_COMMIT_SHORT_HASH:-dev} .
36 changes: 13 additions & 23 deletions .github/workflows/main.yaml → .github/workflows/pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: Main
on: [push, pull_request]
# Continuous Delivery (Packaging) pipeline

name: PKG

on:
push:
branches: [ "master" ]
workflow_dispatch: {}

env:
app_image: hobbyfarm/admin-ui
Expand All @@ -26,33 +32,17 @@ jobs:
- name: Checkout
uses: actions/checkout@master

- name: Setup node_modules cache
id: cache-nodemodules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# cache node_modules to improve performance dramatically
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Install deps
run: npm install

- name: Build
run: npm run build:prod

- name: Build
- name: Create container image
run: |
docker build -f cicd/Dockerfile -t $app_image:${GIT_COMMIT_SHORT_HASH:-dev} .
docker build -f Dockerfile -t $app_image:${GIT_COMMIT_SHORT_HASH:-dev} .
- name: Docker Login
- name: Login container registry
if: fromJSON(env.should_push_image)
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" \
| docker login -u "${{ secrets.REGISTRY_USER }}" --password-stdin
- name: Docker Push
- name: Push container image to registry
if: fromJSON(env.should_push_image)
run: |
safe_ref=$(echo "${{ github.ref_name }}" | sed -e 's/[^a-zA-Z0-9\-\.]/-/g')
Expand All @@ -61,7 +51,7 @@ jobs:
docker tag $app_image:${GIT_COMMIT_SHORT_HASH:-dev} $publish_tag
docker push $publish_tag
- name: Docker Push Latest
- name: Push latest tag
if: fromJSON(env.should_tag_latest)
run: |
docker tag $app_image:${GIT_COMMIT_SHORT_HASH:-dev} $app_image:latest
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@ testem.log
.DS_Store
Thumbs.db

# docker-compose enviornment variables
# local environment variables
/.env

# local configuration file
/src/environments/environment.local.ts
42 changes: 0 additions & 42 deletions CONTRIBUTING.md

This file was deleted.

3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ RUN npm install
COPY . .
RUN npm run build:prod


###### release image #####
FROM nginx:stable-alpine

COPY --from=sdk /app/dist/* /usr/share/nginx/html

# copy staged files
COPY cicd/stage-release/ /
COPY .docker/stage-release/ /

ENTRYPOINT ["entrypoint.sh"]
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Hobbyfarm Admin
# HobbyFarm Admin

This is the admin UI for https://github.com/hobbyfarm
[![CI](https://github.com/hobbyfarm/admin-ui/actions/workflows/ci.yaml/badge.svg?branch=master)](https://github.com/hobbyfarm/admin-ui/actions/workflows/ci.yaml)
[![PKG](https://github.com/hobbyfarm/admin-ui/actions/workflows/pkg.yaml/badge.svg?branch=master)](https://github.com/hobbyfarm/admin-ui/actions/workflows/pkg.yaml)
[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/hobbyfarm/admin-ui?label=Docker)](https://hub.docker.com/r/hobbyfarm/admin-ui)

This is the admin web UI for [HobbyFarm](https://github.com/hobbyfarm). This is a Single Page Application (SPA) developped with Angular.

## Configuration

Expand All @@ -22,4 +26,17 @@ To customize logos, mount them into the container at `/usr/share/nginx/html/asse

## Contributing

If you're interested in contributing, see [CONTRIBUTING.md](CONTRIBUTING.md)
### Local Development

To modify Angular configuration for your local environment, copy `src/environments/environment.local.example.ts` to `src/environments/environment.local.ts` and update the variables as needed. This is particulary useful for `environment.server`, to match your local gargantua server URL.

This web application needs gargantua (backend) to be working, look at [gargantua](https://github.com/hobbyfarm/gargantua/blob/master/CONTRIBUTING.md) for more information. The default authentification is admin/admin.

Execute from a terminal:

```bash
npm install
npm run start:local
```

The Angular server will start a watch loop and listen on [localhost:4200](http://localhost:4200).
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ echo "Building HobbyFarm Amdin UI $PACKAGE_VERSION"

ng build --prod --aot

docker build -t "hobbyfarm/admin-ui" .
docker build -t "hobbyfarm/admin-ui" .

docker tag "hobbyfarm/admin-ui" "hobbyfarm/admin-ui:$PACKAGE_VERSION"

docker push "hobbyfarm/admin-ui:$PACKAGE_VERSION"

echo "HobbyFarm Admin UI built. Pushed version $PACKAGE_VERSION to Docker hub"
echo "HobbyFarm Admin UI built. Pushed version $PACKAGE_VERSION to Docker hub"
12 changes: 0 additions & 12 deletions nginx.conf

This file was deleted.

Loading

0 comments on commit d475483

Please sign in to comment.