2023-04-03 13:53:50 +00:00
|
|
|
name: (CD) Publish docker + s3
|
2022-08-30 08:53:27 +00:00
|
|
|
|
2023-03-24 15:42:33 +00:00
|
|
|
on:
|
|
|
|
workflow_call:
|
|
|
|
inputs:
|
|
|
|
projects:
|
|
|
|
required: true
|
|
|
|
type: string
|
2022-08-30 08:53:27 +00:00
|
|
|
|
|
|
|
jobs:
|
2023-04-03 13:53:50 +00:00
|
|
|
publish-dist:
|
2022-08-30 08:53:27 +00:00
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
2023-03-24 15:42:33 +00:00
|
|
|
app: ${{ fromJSON(inputs.projects) }}
|
|
|
|
name: ${{ matrix.app }}
|
2023-04-03 13:53:50 +00:00
|
|
|
runs-on: ubuntu-22.04
|
2023-04-17 10:45:30 +00:00
|
|
|
timeout-minutes: 20
|
2022-08-30 08:53:27 +00:00
|
|
|
steps:
|
|
|
|
- name: Check out code
|
|
|
|
uses: actions/checkout@v3
|
|
|
|
|
|
|
|
- name: Set up QEMU
|
|
|
|
id: quemu
|
|
|
|
uses: docker/setup-qemu-action@v2
|
|
|
|
|
|
|
|
- name: Available platforms
|
|
|
|
run: echo ${{ steps.qemu.outputs.platforms }}
|
|
|
|
|
|
|
|
- name: Set up Docker Buildx
|
|
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
|
2023-04-03 13:53:50 +00:00
|
|
|
- name: Log in to the Container registry
|
|
|
|
uses: docker/login-action@v2
|
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
2023-04-14 09:47:41 +00:00
|
|
|
- name: Setup node
|
|
|
|
uses: actions/setup-node@v3
|
|
|
|
with:
|
|
|
|
node-version-file: '.nvmrc'
|
|
|
|
# https://stackoverflow.com/questions/61010294/how-to-cache-yarn-packages-in-github-actions
|
|
|
|
cache: yarn
|
|
|
|
|
|
|
|
- name: Cache node modules
|
|
|
|
uses: actions/cache@v3
|
|
|
|
with:
|
|
|
|
path: node_modules
|
|
|
|
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('yarn.lock') }}
|
|
|
|
|
2023-03-23 09:50:23 +00:00
|
|
|
# https://docs.github.com/en/actions/learn-github-actions/contexts
|
2023-04-12 07:38:26 +00:00
|
|
|
- name: Define variables
|
2022-08-30 08:53:27 +00:00
|
|
|
run: |
|
2023-04-14 09:47:41 +00:00
|
|
|
envName=''
|
|
|
|
dockerfile="dist.Dockerfile"
|
2023-04-03 13:53:50 +00:00
|
|
|
if [[ "${{ github.event_name }}" = "push" ]]; then
|
2023-04-12 07:38:26 +00:00
|
|
|
domain="vega.rocks"
|
|
|
|
if [[ "${{ github.ref }}" =~ .*release/.* ]]; then
|
|
|
|
envName="$(echo ${{ github.ref }} | rev | cut -d '/' -f 1 | rev)"
|
|
|
|
if [[ "${{ github.ref }}" =~ .*mainnet.* ]]; then
|
|
|
|
domain="vega.community"
|
2023-04-14 09:47:41 +00:00
|
|
|
if [[ "${{ matrix.app }}" = "trading" ]]; then
|
|
|
|
dockerfile="ipfs.Dockerfile"
|
|
|
|
fi
|
2023-04-12 07:38:26 +00:00
|
|
|
fi
|
|
|
|
elif [[ "${{ github.ref }}" =~ .*develop$ ]]; then
|
|
|
|
envName="stagnet3"
|
|
|
|
fi
|
|
|
|
bucketName="${{ matrix.app }}.${envName}.${domain}"
|
2023-04-14 09:47:41 +00:00
|
|
|
echo BUCKET_NAME=${bucketName} >> $GITHUB_ENV
|
2023-04-03 13:53:50 +00:00
|
|
|
fi
|
2023-04-12 07:38:26 +00:00
|
|
|
nodeVersion=$(cat .nvmrc | head -n 1)
|
2023-04-14 09:47:41 +00:00
|
|
|
echo ENV_NAME=${envName} >> $GITHUB_ENV
|
|
|
|
echo NODE_VERSION=${nodeVersion} >> $GITHUB_ENV
|
|
|
|
echo DOCKERFILE=docker/${dockerfile} >> $GITHUB_ENV
|
|
|
|
|
|
|
|
- name: Build local dist
|
|
|
|
if: ${{ env.DOCKERFILE != 'docker/ipfs.Dockerfile' }}
|
|
|
|
run: |
|
|
|
|
flags=""
|
|
|
|
if [[ ! -z "${{ env.ENV_NAME }}" ]]; then
|
|
|
|
if [[ "${{ env.ENV_NAME }}" != "ops-vega" ]]; then
|
|
|
|
flags="--env=${{ env.ENV_NAME }}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${{ matrix.app }}" = "trading" ]; then
|
|
|
|
yarn nx export trading $flags || (yarn install && yarn nx export trading $flags)
|
|
|
|
DIST_LOCATION=dist/apps/trading/exported
|
|
|
|
else
|
|
|
|
yarn nx build ${{ matrix.app }} $flags || (yarn install && yarn nx build ${{ matrix.app }} $flags)
|
|
|
|
DIST_LOCATION=dist/apps/${{ matrix.app }}
|
|
|
|
fi
|
|
|
|
mv $DIST_LOCATION dist-result
|
|
|
|
tree dist-result
|
2022-08-30 08:53:27 +00:00
|
|
|
|
|
|
|
- name: Build and export to local Docker
|
2023-04-03 13:53:50 +00:00
|
|
|
id: docker_build
|
2023-04-14 13:45:14 +00:00
|
|
|
if: ${{ github.event_name == 'pull_request' || ( env.DOCKERFILE == 'docker/ipfs.Dockerfile' && github.event_name == 'push' ) }}
|
2022-08-30 08:53:27 +00:00
|
|
|
uses: docker/build-push-action@v3
|
|
|
|
with:
|
2023-04-14 09:47:41 +00:00
|
|
|
context: .
|
|
|
|
file: ${{ env.DOCKERFILE }}
|
2023-03-24 15:42:33 +00:00
|
|
|
load: true
|
2023-03-23 09:50:23 +00:00
|
|
|
build-args: |
|
|
|
|
APP=${{ matrix.app }}
|
2023-04-14 09:47:41 +00:00
|
|
|
NODE_VERSION=${{ env.NODE_VERSION }}
|
|
|
|
ENV_NAME=${{ env.ENV_NAME }}
|
2023-03-23 09:50:23 +00:00
|
|
|
tags: |
|
|
|
|
ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:local
|
2022-08-30 08:53:27 +00:00
|
|
|
|
2023-04-14 13:45:14 +00:00
|
|
|
- name: Image digest
|
|
|
|
if: ${{ github.event_name == 'pull_request' || ( env.DOCKERFILE == 'docker/ipfs.Dockerfile' && github.event_name == 'push' ) }}
|
|
|
|
run: echo ${{ steps.docker_build.outputs.digest }}
|
|
|
|
|
2022-08-30 08:53:27 +00:00
|
|
|
- name: Sanity check docker image
|
2023-04-14 13:45:14 +00:00
|
|
|
if: ${{ github.event_name == 'pull_request' || ( env.DOCKERFILE == 'docker/ipfs.Dockerfile' && github.event_name == 'push' ) }}
|
2022-08-30 08:53:27 +00:00
|
|
|
run: |
|
2023-03-23 09:50:23 +00:00
|
|
|
echo "Check ipfs-hash"
|
2023-04-14 09:47:41 +00:00
|
|
|
if [[ "${{ env.DOCKERFILE }}" = "docker/ipfs.Dockerfile" ]]; then
|
|
|
|
docker run --rm ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:local cat /ipfs-hash
|
|
|
|
fi
|
2023-04-03 13:53:50 +00:00
|
|
|
|
2023-03-23 09:50:23 +00:00
|
|
|
echo "List html directory"
|
2023-04-12 07:38:26 +00:00
|
|
|
docker run --rm ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:local sh -c 'apk add --update tree; tree .'
|
2023-03-23 09:50:23 +00:00
|
|
|
|
2023-04-12 07:38:26 +00:00
|
|
|
- name: Copy dist to local filesystem
|
2023-04-14 13:45:14 +00:00
|
|
|
if: ${{ env.DOCKERFILE == 'docker/ipfs.Dockerfile' && github.event_name == 'push' }}
|
2023-04-12 07:38:26 +00:00
|
|
|
run: |
|
2023-04-03 13:53:50 +00:00
|
|
|
docker create --name=dist ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:local
|
|
|
|
docker cp dist:/usr/share/nginx/html dist
|
2022-08-30 08:53:27 +00:00
|
|
|
|
2023-04-12 07:38:26 +00:00
|
|
|
echo "check local dist files"
|
2023-04-14 13:45:14 +00:00
|
|
|
tree dist/html
|
|
|
|
mv dist/html dist-result
|
2023-04-03 13:53:50 +00:00
|
|
|
|
|
|
|
- name: Publish dist as docker image
|
2022-08-30 08:53:27 +00:00
|
|
|
uses: docker/build-push-action@v3
|
2023-04-03 13:53:50 +00:00
|
|
|
if: ${{ github.event_name == 'pull_request' }}
|
2022-08-30 08:53:27 +00:00
|
|
|
with:
|
2023-04-14 09:47:41 +00:00
|
|
|
context: .
|
|
|
|
file: ${{ env.DOCKERFILE }}
|
2023-03-23 09:50:23 +00:00
|
|
|
push: true
|
|
|
|
build-args: |
|
|
|
|
APP=${{ matrix.app }}
|
2023-04-14 09:47:41 +00:00
|
|
|
NODE_VERSION=${{ env.NODE_VERSION }}
|
|
|
|
ENV_NAME=${{ env.ENV_NAME }}
|
2022-08-30 08:53:27 +00:00
|
|
|
tags: |
|
2023-04-03 13:53:50 +00:00
|
|
|
ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:${{ github.event.pull_request.head.sha || github.sha }}
|
|
|
|
|
2023-04-12 07:38:26 +00:00
|
|
|
# bucket creation in github.com/vegaprotocol/terraform//frontend
|
|
|
|
- name: Publish dist to s3
|
|
|
|
uses: jakejarvis/s3-sync-action@master
|
|
|
|
if: ${{ github.event_name == 'push' }}
|
|
|
|
with:
|
|
|
|
args: --acl private --follow-symlinks --delete
|
|
|
|
env:
|
2023-04-14 13:00:20 +00:00
|
|
|
AWS_S3_BUCKET: ${{ env.BUCKET_NAME }}
|
2023-04-12 07:38:26 +00:00
|
|
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
|
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
|
|
AWS_REGION: 'eu-west-1'
|
2023-04-14 13:45:14 +00:00
|
|
|
SOURCE_DIR: 'dist-result'
|
2022-08-30 08:53:27 +00:00
|
|
|
|
2023-03-24 15:42:33 +00:00
|
|
|
- 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 }}
|