feat(explorer,trading,governance): use nx to know which apps needs building (#3267)

This commit is contained in:
Mikołaj Młodzikowski 2023-03-24 16:42:33 +01:00 committed by GitHub
parent 8214858685
commit 19f8fa909e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 38 deletions

View File

@ -3,3 +3,7 @@ apps/**/node_modules/*
tmp/* tmp/*
.dockerignore .dockerignore
dockerfiles dockerfiles
node_modules
.git
.github
.vscode

View File

@ -1,3 +1,4 @@
name: Cypress Run
on: on:
workflow_call: workflow_call:
inputs: inputs:
@ -17,6 +18,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
project: ${{ fromJSON(inputs.projects) }} project: ${{ fromJSON(inputs.projects) }}
name: ${{ matrix.project }}
runs-on: self-hosted-runner runs-on: self-hosted-runner
timeout-minutes: 30 timeout-minutes: 30
steps: steps:

View File

@ -1,4 +1,4 @@
name: Cypress tests - PR name: PR Validations
on: on:
push: push:
@ -20,14 +20,16 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Check node version
id: node-version
run: |
npmVersion=$(cat .nvmrc | head -n 1)
echo ::set-output name=npmVersion::${npmVersion}
- name: Setup node - name: Setup node
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with:
- name: Remove package.json & yarn.lock to avoid installing everything node-version: ${{ steps.node-version.outputs.npmVersion }}
run: rm package.json yarn.lock
- name: Install nx
run: yarn add nx
# Check SHAs # Check SHAs
- name: Derive appropriate SHAs for base and head for `nx affected` commands - name: Derive appropriate SHAs for base and head for `nx affected` commands
@ -39,38 +41,51 @@ jobs:
# See affected apps # See affected apps
- name: See affected apps - name: See affected apps
run: | run: |
nx_version=$(cat package.json | grep '"nx"' | cut -d ':' -f 2 | tr -d '",[:space:]')
rm package.json yarn.lock
yarn add nx@$nx_version
affected=$(yarn nx print-affected --base=${{ env.NX_BASE }} --head=${{ env.NX_HEAD }} --select=projects) affected=$(yarn nx print-affected --base=${{ env.NX_BASE }} --head=${{ env.NX_HEAD }} --select=projects)
echo -n "Affected projects: $affected" echo -n "Affected projects: $affected"
projects="" projects_e2e=""
if [[ $affected == *"governance"* ]]; then projects+='"governance-e2e" '; fi if [[ $affected == *"governance"* ]]; then projects_e2e+='"governance-e2e" '; fi
if [[ $affected == *"trading"* ]]; then projects+='"trading-e2e" '; fi if [[ $affected == *"trading"* ]]; then projects_e2e+='"trading-e2e" '; fi
if [[ $affected == *"explorer"* ]]; then projects+='"explorer-e2e" '; fi if [[ $affected == *"explorer"* ]]; then projects_e2e+='"explorer-e2e" '; fi
if [[ -z "$projects" ]]; then projects+='"governance-e2e" "trading-e2e" "explorer-e2e" '; fi if [[ -z "$projects_e2e" ]]; then projects_e2e+='"governance-e2e" "trading-e2e" "explorer-e2e" '; fi
projects=${projects%?} projects_e2e=${projects_e2e%?}
projects=[${projects// /,}] projects_e2e=[${projects_e2e// /,}]
echo PROJECTS=$projects >> $GITHUB_ENV echo PROJECTS_E2E=$projects_e2e >> $GITHUB_ENV
echo PROJECTS=$(echo $projects_e2e | sed 's|-e2e||g') >> $GITHUB_ENV
outputs: outputs:
projects: ${{ env.PROJECTS }} projects: ${{ env.PROJECTS }}
projects-e2e: ${{ env.PROJECTS_E2E }}
run: run-cypress:
needs: pr needs: pr
if: ${{ needs.pr.outputs.projects != '[]' }} if: ${{ needs.pr.outputs.projects != '[]' }}
uses: ./.github/workflows/cypress-run.yml uses: ./.github/workflows/cypress-run.yml
secrets: inherit secrets: inherit
with: with:
projects: ${{ needs.pr.outputs.projects }} projects: ${{ needs.pr.outputs.projects-e2e }}
tags: '@smoke @regression' tags: '@smoke @regression'
run-docker-build:
needs: pr
if: ${{ needs.pr.outputs.projects != '[]' }}
uses: ./.github/workflows/publish-docker-containers.yml
secrets: inherit
with:
projects: ${{ needs.pr.outputs.projects }}
# Report single result at the end, to avoid mess with required checks in PR # Report single result at the end, to avoid mess with required checks in PR
result: result:
if: ${{ always() }} if: ${{ always() }}
needs: run needs: run-cypress
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Cypress result name: Cypress result
steps: steps:
- run: | - run: |
result="${{ needs.run.result }}" result="${{ needs.run-cypress.result }}"
if [[ $result == "success" || $result == "skipped" ]]; then if [[ $result == "success" || $result == "skipped" ]]; then
exit 0 exit 0
else else

View File

@ -1,16 +1,19 @@
name: Publish docker containers name: Docker build
'on': on:
pull_request: workflow_call:
inputs:
projects:
required: true
type: string
jobs: jobs:
master: master:
strategy: strategy:
fail-fast: false fail-fast: false
# to be replaced by nix: https://github.com/vegaprotocol/frontend-monorepo/blob/develop/tools/ipfs-deploy.js#L106-L108
matrix: matrix:
app: ${{ fromJson('["explorer"]') }} app: ${{ fromJSON(inputs.projects) }}
name: Build the ${{ matrix.app }} image name: ${{ matrix.app }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out code - name: Check out code
@ -45,13 +48,10 @@ jobs:
- name: Build and export to local Docker - name: Build and export to local Docker
uses: docker/build-push-action@v3 uses: docker/build-push-action@v3
with: with:
context: . load: true
push: false
file: dockerfiles/Dockerfile
build-args: | build-args: |
APP=${{ matrix.app }} APP=${{ matrix.app }}
NODE_VERSION=${{ steps.tags.outputs.npmVersion }} NODE_VERSION=${{ steps.tags.outputs.npmVersion }}
load: true
tags: | tags: |
ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:local ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:local
@ -75,9 +75,7 @@ jobs:
id: docker_build id: docker_build
uses: docker/build-push-action@v3 uses: docker/build-push-action@v3
with: with:
context: .
push: true push: true
file: dockerfiles/Dockerfile
build-args: | build-args: |
APP=${{ matrix.app }} APP=${{ matrix.app }}
NODE_VERSION=${{ steps.tags.outputs.npmVersion }} NODE_VERSION=${{ steps.tags.outputs.npmVersion }}
@ -85,5 +83,12 @@ jobs:
ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:latest ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:latest
ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:${{ steps.tags.outputs.version }} ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:${{ steps.tags.outputs.version }}
- name: Add preview label
uses: actions-ecosystem/action-add-labels@v1
if: ${{ github.event_name == 'pull_request' }}
with:
labels: ${{ matrix.app }}-preview
number: ${{ github.event.number }}
- name: Image digest - name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }} run: echo ${{ steps.docker_build.outputs.digest }}

View File

@ -4,13 +4,15 @@ FROM --platform=amd64 node:${NODE_VERSION}-alpine3.16 as build
WORKDIR /app WORKDIR /app
# Argument to allow building of different apps # Argument to allow building of different apps
ARG APP ARG APP
ENV PATH /app/node_modules/.bin:$PATH RUN apk add --update --no-cache \
COPY package.json ./ python3 \
COPY yarn.lock ./ make \
gcc \
g++
COPY . ./ COPY . ./
RUN apk add python3 make gcc g++
RUN yarn --network-timeout 100000 --pure-lockfile RUN yarn --network-timeout 100000 --pure-lockfile
RUN yarn nx build ${APP} --network-timeout 100000 --pure-lockfile # work around for different build process in trading
RUN sh ./docker-build.sh
# Server environment # Server environment
# if this fails you need to docker pull nginx:1.23-alpine and pin new SHA # if this fails you need to docker pull nginx:1.23-alpine and pin new SHA
@ -25,7 +27,7 @@ CMD ["/entrypoint.sh"]
# Copy dist # Copy dist
WORKDIR /usr/share/nginx/html WORKDIR /usr/share/nginx/html
COPY --from=build /app/dist/apps/${APP} /usr/share/nginx/html
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist/apps/${APP} /usr/share/nginx/html
COPY ./apps/${APP}/.env .env COPY ./apps/${APP}/.env .env
RUN ipfs init && echo "$(ipfs add -rQ .)" > ipfs-hash RUN ipfs init && echo "$(ipfs add -rQ .)" > ipfs-hash

10
docker-build.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh -eux
export PATH="/app/node_modules/.bin:$PATH"
if [ "${APP}" = "trading" ]; then
yarn nx export ${APP} --network-timeout 100000 --pure-lockfile
mv /app/dist/apps/trading/exported/ /app/tmp
rm -rf /app/dist/apps/trading
mv /app/tmp /app/dist/apps/trading
else
yarn nx build ${APP} --network-timeout 100000 --pure-lockfile
fi

View File

@ -7,6 +7,10 @@ mkdir -p $(dirname $env_file)
rm -rf $env_file || echo "no file to delete" rm -rf $env_file || echo "no file to delete"
touch $env_file touch $env_file
env_vars_file=/usr/share/nginx/html/.env
sed -i '/^#/d' $env_vars_file # remove comment lines
sed -i '/^$/d' $env_vars_file # remove empty lines
# Add assignment # Add assignment
echo "window._env_ = {" >> $env_file echo "window._env_ = {" >> $env_file
@ -29,7 +33,7 @@ do
if [ ! -z "$varname" ]; then if [ ! -z "$varname" ]; then
echo " $varname: \"$value\"," >> $env_file echo " $varname: \"$value\"," >> $env_file
fi fi
done < /usr/share/nginx/html/.env done < $env_vars_file
echo "}" >> $env_file echo "}" >> $env_file