From 35b540c8215029371c62fdfbc887e11d2a99cc3b Mon Sep 17 00:00:00 2001 From: Eamon Bauman Date: Wed, 26 Oct 2022 17:17:25 -0400 Subject: [PATCH] fixing cicd (#137) * fixing cicd * FORGOT THE DOT! * fixed dockerfile * Revert "fixed dockerfile" This reverts commit e374432cbe3a15b01fabc537a273f7112ace5669. * fixed cicd --- .dockerignore | 1 - .github/workflows/main.yaml | 23 +++-- cicd/docker/Dockerfile => Dockerfile | 0 cicd/Dockerfile | 11 +++ cicd/docker-local/Dockerfile | 26 ------ cicd/docker-local/stage/etc/fixuid/config.yml | 6 -- cicd/docker-local/stage/usr/local/bin/run.sh | 14 --- .../etc/nginx/conf.d/default.conf | 0 .../stage-release/usr/local/bin/entrypoint.sh | 0 compose.sh | 88 ------------------- docker-compose.yaml | 31 ------- 11 files changed, 25 insertions(+), 175 deletions(-) rename cicd/docker/Dockerfile => Dockerfile (100%) create mode 100644 cicd/Dockerfile delete mode 100644 cicd/docker-local/Dockerfile delete mode 100644 cicd/docker-local/stage/etc/fixuid/config.yml delete mode 100755 cicd/docker-local/stage/usr/local/bin/run.sh rename cicd/{docker => }/stage-release/etc/nginx/conf.d/default.conf (100%) rename cicd/{docker => }/stage-release/usr/local/bin/entrypoint.sh (100%) delete mode 100755 compose.sh delete mode 100644 docker-compose.yaml diff --git a/.dockerignore b/.dockerignore index c361627e..16ef8145 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,2 @@ /.git -/dist /node_modules diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 61bfe2ff..fa76f1e3 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -3,8 +3,6 @@ on: [push, pull_request] env: app_image: hobbyfarm/admin-ui - sdk_image: hobbyfarm/admin-ui-sdk - dockerfile: cicd/docker/Dockerfile should_push_image: |- ${{ @@ -29,14 +27,21 @@ jobs: - name: Checkout uses: actions/checkout@master + - name: Setup npm cache + uses: actions/setup-node@v3 + with: + node-version: 16 + cache: 'npm' + + - name: Install deps + run: npm install + - name: Build - run: | - docker build -f $dockerfile --tag $sdk_image --target sdk . + run: npm run build:prod - - name: Build Release - if: fromJSON(env.should_push_image) + - name: Build run: | - docker build -f $dockerfile --tag $app_image . + docker build -f cicd/Dockerfile -t $app_image:${GIT_COMMIT_SHORT_HASH:-dev} . - name: Docker Login if: fromJSON(env.should_push_image) @@ -50,9 +55,9 @@ jobs: safe_ref=$(echo "${{ github.ref_name }}" | sed -e 's/[^a-zA-Z0-9\-\.]/-/g') publish_tag=$app_image:$safe_ref - docker tag $app_image $publish_tag + docker tag $app_image:${GIT_COMMIT_SHORT_HASH:-dev} $publish_tag docker push $publish_tag - name: Docker Push Latest if: fromJSON(env.should_tag_latest) - run: docker push $app_image + run: docker push $app_image:latest diff --git a/cicd/docker/Dockerfile b/Dockerfile similarity index 100% rename from cicd/docker/Dockerfile rename to Dockerfile diff --git a/cicd/Dockerfile b/cicd/Dockerfile new file mode 100644 index 00000000..730d7e7c --- /dev/null +++ b/cicd/Dockerfile @@ -0,0 +1,11 @@ +# Should only be used with GitHub Actions cicd +# 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/ / + +ENTRYPOINT ["entrypoint.sh"] diff --git a/cicd/docker-local/Dockerfile b/cicd/docker-local/Dockerfile deleted file mode 100644 index 7add9283..00000000 --- a/cicd/docker-local/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -FROM node:lts-alpine - -# install deps -RUN apk add --no-cache \ - curl - -# install fixuid -RUN curl -SsL https://github.com/boxboat/fixuid/releases/download/v0.4/fixuid-0.4-linux-amd64.tar.gz | tar -C /usr/local/bin -xzf - \ - && chown root:root /usr/local/bin/fixuid \ - && chmod 4755 /usr/local/bin/fixuid - -# create app dir and set owner -RUN mkdir -p /app/node_modules \ - && chown -R node:node /app - -USER node:node - -# create npm cache dir -RUN mkdir -p ~/.npm - -# copy staged / files -COPY stage/ / - -WORKDIR /app -ENTRYPOINT ["fixuid"] -CMD ["run.sh"] diff --git a/cicd/docker-local/stage/etc/fixuid/config.yml b/cicd/docker-local/stage/etc/fixuid/config.yml deleted file mode 100644 index 354ccbfb..00000000 --- a/cicd/docker-local/stage/etc/fixuid/config.yml +++ /dev/null @@ -1,6 +0,0 @@ -user: node -group: node -paths: -- /home/node -- /home/node/.npm -- /app/node_modules diff --git a/cicd/docker-local/stage/usr/local/bin/run.sh b/cicd/docker-local/stage/usr/local/bin/run.sh deleted file mode 100755 index 66ed4d18..00000000 --- a/cicd/docker-local/stage/usr/local/bin/run.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -set -e - -trap : TERM INT - -( - echo 'running npm install...' - npm install - echo 'starting...' - npm run start:local:docker -) & - -wait diff --git a/cicd/docker/stage-release/etc/nginx/conf.d/default.conf b/cicd/stage-release/etc/nginx/conf.d/default.conf similarity index 100% rename from cicd/docker/stage-release/etc/nginx/conf.d/default.conf rename to cicd/stage-release/etc/nginx/conf.d/default.conf diff --git a/cicd/docker/stage-release/usr/local/bin/entrypoint.sh b/cicd/stage-release/usr/local/bin/entrypoint.sh similarity index 100% rename from cicd/docker/stage-release/usr/local/bin/entrypoint.sh rename to cicd/stage-release/usr/local/bin/entrypoint.sh diff --git a/compose.sh b/compose.sh deleted file mode 100755 index d4b5e611..00000000 --- a/compose.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/sh -e - -cd $(dirname $0) - -build_arg="" -script="$0" - -up_usage() { -cat >&2 < - -options: - --build - build new container - -h, --help - print this message - -EOF -} - -up() { - while test $# -gt 0 - do - case "$1" in - -h | --help) - up_usage - exit 0 - ;; - --build) - build_arg="--build" - ;; - *) - up_usage - exit 1 - ;; - esac - shift - done - - docker-compose up $build_arg -} - -stop() { - docker-compose stop -} - -destroy() { - docker-compose down -v -} - -usage() { -cat >&2 <<-EOF -manage local HobbyFarm Admin UI development environment - - usage: $script - -where is one of: - - up - create or start Admin UI - stop - stop Admin UI - destroy - destroy Admin UI - -options: - -h, --help - print this message - -EOF -} - -case "$1" in - -h | --help) - usage - exit 0 - ;; - up) - shift - up "$@" - ;; - stop) - stop - ;; - destroy) - destroy - ;; - *) - usage - exit 1 - ;; -esac diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index 29b7e819..00000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,31 +0,0 @@ -version: "3.4" - -services: - - admin-ui: - build: - context: ./cicd/docker-local - container_name: hf-admin-ui - environment: - CHOKIDAR_USEPOLLING: ${CHOKIDAR_USEPOLLING:-true} - ports: - - "${ADMIN_UI_PORT:-16205}:4200" - user: ${FIXUID:-1000}:${FIXGID:-1000} - volumes: - # bind-mount files in root needed by npm - - ./angular.json:/app/angular.json - - ./browserslist:/app/browserslist - - ./package.json:/app/package.json - - ./package-lock.json:/app/package-lock.json - - ./setup-local.js:/app/setup-local.js - - ./tsconfig.json:/app/tsconfig.json - - ./tslint.json:/app/tslint.json - # bind-mount src directory - - ./src:/app/src - # volumes for npm cache and node_models - - npm-cache:/home/node/.npm - - node-modules-cache:/app/node_modules - -volumes: - npm-cache: {} - node-modules-cache: {}