Skip to content

Commit

Permalink
devops: fix harbor build action
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Garcia Garcia <[email protected]>
  • Loading branch information
miguelgrc committed May 15, 2024
1 parent 34e718c commit 055af51
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27,670 deletions.
45 changes: 4 additions & 41 deletions .github/workflows/harbour-build-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ name: Build and export CAP UI image

on:
push:
branches: ['master', 'dev', 'qa', 'test']
paths:
- "ui/**"
- ".github/workflows/ui-test.yml"
branches: ["master", "dev", "qa", "test", "with-formule"]
# paths:
# - "ui/**"
# - ".github/workflows/ui-test.yml"

jobs:
build-image:
needs: UITest
name: Build and export ui image
runs-on: ubuntu-20.04
outputs:
Expand Down Expand Up @@ -43,39 +42,3 @@ jobs:
CAP_PIWIK_SITEID_PROD=${{ secrets.CAP_PIWIK_SITEID_PROD }}
CAP_PIWIK_SITEID_QA=${{ secrets.CAP_PIWIK_SITEID_QA }}
CAP_PIWIK_SITEID_TEST=${{ secrets.CAP_PIWIK_SITEID_TEST }}
- id: build-ui-e2e
name: Build and export for end to end image
uses: cern-sis/gh-workflows/.github/actions/[email protected]
if: ${{ steps.get_branch.outputs.BRANCH_NAME }} == 'qa'
with:
dockerfile: ./docker/harbour/ui/Dockerfile
platforms: linux/amd64,linux/arm64
image: cern-sis/cap-ui
registry: registry.cern.ch
cache: false
tags: qa-e2e
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
build-args: |
BRANCH_NAME=${{ steps.get_branch.outputs.BRANCH_NAME }}
ENABLE_E2E=True
PIWIK_ENV=${{ steps.get_branch.outputs.BRANCH_NAME }}
CAP_PIWIK_URL=${{ secrets.CAP_PIWIK_URL }}
CAP_PIWIK_SITEID_QA=${{ secrets.CAP_PIWIK_SITEID_QA }}
deploy:
needs: build-image
name: update-image
runs-on: ubuntu-20.04

steps:
- name: send event
uses: cern-sis/gh-workflows/.github/actions/[email protected]
with:
event-type: update
token: ${{ secrets.PAT_FIRE_EVENTS_ON_CERN_SIS_KUBERNETES_CAP }}
repo: cern-sis/kubernetes-cap
images: |
cern-sis/cap-ui@{{ needs.build-image.outputs.image-id }}
114 changes: 34 additions & 80 deletions docker/harbour/ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,50 +1,10 @@
FROM nginx:1.24


RUN apt-get update
RUN apt-get install -y curl bash


RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs
FROM node:18-alpine as build

RUN apt-get update && apt-get -y install git python g++ make
RUN npm install --global yarn
RUN apk add --no-cache git

ENV WORKING_DIR=/tmp/cap
ENV NGINX_HTML_DIR=/usr/share/nginx/html
ENV NODE_OPTIONS="--max-old-space-size=8192"

RUN mkdir -p $NGINX_HTML_DIR

# We invalidate cache always because there is no easy way for now to detect
# if something in the whole git repo changed. For docker git clone <url> <dir>
# is always the same so it caches it.
ARG CACHE_DATE=$(date)

# get the code at a specific commit
RUN git clone https://github.com/cernanalysispreservation/analysispreservation.cern.ch.git $WORKING_DIR/

WORKDIR $WORKING_DIR/

ARG BRANCH_NAME

RUN echo $BRANCH_NAME

RUN git fetch --all

RUN if [ ! -z $BRANCH_NAME ]; then \
# run commands to checkout a branch
echo "Checkout branch $BRANCH_NAME" && \
git checkout $BRANCH_NAME && \
git pull origin $BRANCH_NAME; \
fi

RUN git log -10 --pretty=oneline --decorate

RUN cp -rfp $WORKING_DIR/docker/nginx/nginx.conf /etc/nginx/nginx.conf

WORKDIR $WORKING_DIR/ui
WORKDIR $WORKING_DIR

ARG PIWIK_ENV=dev
ARG ENABLE_E2E
Expand All @@ -61,74 +21,68 @@ ARG PIWIK_SITEID_PROD
ARG PIWIK_SITEID_QA
ARG PIWIK_SITEID_TEST

RUN echo "" >> $WORKING_DIR/ui/cap-react/.env
RUN echo "" >> $WORKING_DIR/ui/cap-react/.env
RUN echo "PIWIK_URL=$CAP_PIWIK_URL" >> $WORKING_DIR/ui/cap-react/.env
RUN echo "ENABLE_E2E=$ENABLE_E2E" >> $WORKING_DIR/ui/cap-react/.env

RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN mkdir -p ui/cap-react
RUN echo "PIWIK_URL=$CAP_PIWIK_URL" >> ui/cap-react/.env
RUN echo "ENABLE_E2E=$ENABLE_E2E" >> ui/cap-react/.env

RUN if [[ $PIWIK_ENV == "dev" ]]; then \
echo "PIWIK_SITEID=$CAP_PIWIK_SITEID_DEV" >> $WORKING_DIR/ui/cap-react/.env; \
echo "PIWIK_SITEID=$CAP_PIWIK_SITEID_DEV" >> ui/cap-react/.env; \
fi

RUN if [[ $PIWIK_ENV == "prod" ]]; then \
echo "PIWIK_SITEID=$CAP_PIWIK_SITEID_PROD" >> $WORKING_DIR/ui/cap-react/.env; \
echo "PIWIK_SITEID=$CAP_PIWIK_SITEID_PROD" >> ui/cap-react/.env; \
fi

RUN if [[ $PIWIK_ENV == "qa" ]]; then \
echo "PIWIK_SITEID=$CAP_PIWIK_SITEID_QA" >> $WORKING_DIR/ui/cap-react/.env; \
echo "PIWIK_SITEID=$CAP_PIWIK_SITEID_QA" >> ui/cap-react/.env; \
fi

RUN if [[ $PIWIK_ENV == "test" ]]; then \
echo "PIWIK_SITEID=$CAP_PIWIK_SITEID_TEST" >> $WORKING_DIR/ui/cap-react/.env; \
echo "PIWIK_SITEID=$CAP_PIWIK_SITEID_TEST" >> ui/cap-react/.env; \
fi


RUN echo "=========================="
RUN echo $CAP_PIWIK_SITEID_TEST
RUN echo $PIWIK_SITEID_TEST
RUN echo "=========================="
RUN less $WORKING_DIR/ui/cap-react/.env
RUN cat ui/cap-react/.env
RUN echo "=========================="

RUN yarn config set cache ~/.my-yarn-cache-dir
WORKDIR $WORKING_DIR/ui

RUN pwd
# build CAP UI
COPY ./ui ${WORKING_DIR}/ui
RUN yarn install
# RUN yarn upgrade

RUN yarn workspace cap-react build
RUN pwd
RUN ls ./cap-react/dist/*
RUN cp -rfp ./cap-react/dist/* $NGINX_HTML_DIR

# build docs general
# build general docs
COPY ./docs ${WORKING_DIR}/docs
WORKDIR $WORKING_DIR/docs

RUN yarn
RUN yarn install
RUN yarn build

RUN mkdir -p $NGINX_HTML_DIR/docs/general
RUN cp -rfp ./_book/* $NGINX_HTML_DIR/docs/general


# build docs API
# build API docs
RUN git clone https://github.com/cernanalysispreservation/cap-api-docs.git $WORKING_DIR/cap-api-docs/
WORKDIR $WORKING_DIR/cap-api-docs

RUN npm install
RUN npm install --maxsockets 1
RUN npm run build

RUN mkdir -p $NGINX_HTML_DIR/docs/api
RUN cp -rfp ./web_deploy/* $NGINX_HTML_DIR/docs/api


# build docs client
# build client docs
RUN git clone https://github.com/cernanalysispreservation/cap-client.git $WORKING_DIR/cap-client/
WORKDIR $WORKING_DIR/cap-client/docs

RUN yarn
RUN yarn install
RUN yarn build

RUN mkdir -p $NGINX_HTML_DIR/docs/client
RUN cp -rfp ./_book/* $NGINX_HTML_DIR/docs/client

FROM nginx:1.24

ENV WORKING_DIR=/tmp/cap
ENV NGINX_HTML_DIR=/usr/share/nginx/html/
RUN mkdir -p $NGINX_HTML_DIR

COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
COPY --from=build ${WORKING_DIR}/ui/cap-react/dist/ $NGINX_HTML_DIR
COPY --from=build ${WORKING_DIR}/docs/_book/ $NGINX_HTML_DIR/docs/general
COPY --from=build ${WORKING_DIR}/cap-api-docs/web_deploy/ $NGINX_HTML_DIR/docs/api
COPY --from=build ${WORKING_DIR}/cap-client/docs/_book/ $NGINX_HTML_DIR/docs/client
1 change: 0 additions & 1 deletion docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ http {
image/x-icon
text/cache-manifest
text/css
text/html
text/javascript
text/plain
text/vcard
Expand Down
Loading

0 comments on commit 055af51

Please sign in to comment.