From 05d8cb36050ecc4c3eb28a8b0269d460edb243df Mon Sep 17 00:00:00 2001 From: Dexter Edwards Date: Mon, 25 Jul 2022 09:48:29 +0100 Subject: [PATCH] Feat: Containerised docker images (#700) * chore: first pass at config file * ci: pass app version * ci: remove workflows that take a while to run to not waste build mins * ci: run all steps all the time * ci: correct tags * ci: correct output syntax * ci: use quotes * ci: fix build platform * ci: only build amd as PoC * ci: add push true to step * ci: publish trading and token containers * fix: use correct environement variable names * feat: separate dockerfiles for CRA based apps and next apps * chore: correct path * fix: incorrect asset path * ci: build for both platforms * ci: publish * ci: add missing deps * ci: rename pipelines * ci: rename * ci: publish on tag only * ci: remove additional vs * Revert "ci: remove workflows that take a while to run to not waste build mins" This reverts commit 7054367ba039f3857c06680baad0ac35a65a2f63. * chore: remove comment * chore: revert accientally committed change --- .github/workflows/publish-containers-cra.yml | 60 +++++++++++++++++++ .github/workflows/publish-containers-next.yml | 60 +++++++++++++++++++ Dockerfile => Dockerfile.cra | 1 + Dockerfile.next | 30 ++++++++++ apps/trading/pages/_app.page.tsx | 2 +- env-config.js | 19 +----- .../src/utils/compile-environment.ts | 4 +- 7 files changed, 156 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/publish-containers-cra.yml create mode 100644 .github/workflows/publish-containers-next.yml rename Dockerfile => Dockerfile.cra (95%) create mode 100644 Dockerfile.next diff --git a/.github/workflows/publish-containers-cra.yml b/.github/workflows/publish-containers-cra.yml new file mode 100644 index 000000000..4e43e3289 --- /dev/null +++ b/.github/workflows/publish-containers-cra.yml @@ -0,0 +1,60 @@ +name: Publish NextJs containers + +'on': + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+-pre[0-9]+' + +jobs: + master: + strategy: + matrix: + build-platform: ['linux/amd64'] + app: ['trading'] + name: Build the ${{ inputs.image_name }} image + runs-on: ubuntu-latest + steps: + - name: Set output + id: vars + run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} + - name: Check output + env: + RELEASE_VERSION: ${{ steps.vars.outputs.tag }} + run: | + echo $RELEASE_VERSION + echo ${{ steps.vars.outputs.tag }} + - uses: actions/checkout@v3 + - name: Set up QEMU + id: quemu + uses: docker/setup-qemu-action@v2 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Collect images data + id: tags + run: | + echo '::set-output name=current::vegaprotocol/${{ matrix.app }}:${{ steps.vars.outputs.tag }}' + echo '::set-output name=latest::vegaprotocol/${{ matrix.app }}:latest' + + - name: Echo tags + run: | + echo ${{ steps.tags.outputs.latest }} + echo ${{ steps.tags.outputs.current }} + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Docker build + uses: docker/build-push-action@v3 + with: + context: '.' + file: './Dockerfile.next' + build-args: 'APP=${{ matrix.app }}' + platforms: ${{ matrix.build-platform }} + tags: ${{ steps.tags.outputs.latest }},${{ steps.tags.outputs.current }} + push: true diff --git a/.github/workflows/publish-containers-next.yml b/.github/workflows/publish-containers-next.yml new file mode 100644 index 000000000..23e726d03 --- /dev/null +++ b/.github/workflows/publish-containers-next.yml @@ -0,0 +1,60 @@ +name: Publish CRA containers + +'on': + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+-pre[0-9]+' + +jobs: + master: + strategy: + matrix: + build-platform: ['linux/amd64'] + app: ['explorer', 'token'] + name: Build the ${{ inputs.image_name }} image + runs-on: ubuntu-latest + steps: + - name: Set output + id: vars + run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} + - name: Check output + env: + RELEASE_VERSION: ${{ steps.vars.outputs.tag }} + run: | + echo $RELEASE_VERSION + echo ${{ steps.vars.outputs.tag }} + - uses: actions/checkout@v3 + - name: Set up QEMU + id: quemu + uses: docker/setup-qemu-action@v2 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Collect images data + id: tags + run: | + echo '::set-output name=current::vegaprotocol/${{ matrix.app }}:${{ steps.vars.outputs.tag }}' + echo '::set-output name=latest::vegaprotocol/${{ matrix.app }}:latest' + + - name: Echo tags + run: | + echo ${{ steps.tags.outputs.latest }} + echo ${{ steps.tags.outputs.current }} + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Docker build + uses: docker/build-push-action@v3 + with: + context: '.' + file: './Dockerfile.cra' + build-args: 'APP=${{ matrix.app }}' + platforms: ${{ matrix.build-platform }} + tags: ${{ steps.tags.outputs.latest }},${{ steps.tags.outputs.current }} + push: true diff --git a/Dockerfile b/Dockerfile.cra similarity index 95% rename from Dockerfile rename to Dockerfile.cra index 986948304..d2f5a237f 100644 --- a/Dockerfile +++ b/Dockerfile.cra @@ -7,6 +7,7 @@ ENV PATH /app/node_modules/.bin:$PATH COPY package.json ./ COPY yarn.lock ./ COPY . ./ +RUN apk add python3 make gcc g++ RUN yarn RUN yarn nx build $APP diff --git a/Dockerfile.next b/Dockerfile.next new file mode 100644 index 000000000..b886bb99c --- /dev/null +++ b/Dockerfile.next @@ -0,0 +1,30 @@ +# Build container +FROM node:16.14.0-alpine as build +WORKDIR /app +# Argument to allow building of different apps +ARG APP +ENV PATH /app/node_modules/.bin:$PATH +COPY package.json ./ +COPY yarn.lock ./ +COPY . ./ +RUN apk add python3 make gcc g++ +RUN yarn +RUN yarn nx export $APP + +# Production environment +FROM nginx:stable-alpine +ARG APP +COPY --from=build /app/dist/apps/$APP/exported /usr/share/nginx/html +COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 + +WORKDIR /usr/share/nginx/html +COPY ./env.sh . +COPY ./apps/$APP/.env .env + +# Add bash +RUN apk add --no-cache bash + +RUN chmod +x ./env.sh +CMD ["/bin/bash", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""] diff --git a/apps/trading/pages/_app.page.tsx b/apps/trading/pages/_app.page.tsx index 2c32fd261..dc16cabfc 100644 --- a/apps/trading/pages/_app.page.tsx +++ b/apps/trading/pages/_app.page.tsx @@ -93,7 +93,7 @@ function VegaTradingApp(props: AppProps) { {['1', 'true'].includes(process.env['NX_USE_ENV_OVERRIDES'] || '') ? ( /* eslint-disable-next-line @next/next/no-sync-scripts */ -