name: (CD) Publish docker + s3 on: workflow_call: inputs: projects: required: true type: string jobs: publish-dist: strategy: fail-fast: false matrix: app: ${{ fromJSON(inputs.projects) }} name: ${{ matrix.app }} runs-on: ubuntu-22.04 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 - name: Log in to the Container registry uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} # https://docs.github.com/en/actions/learn-github-actions/contexts - name: Check node version id: tags run: | nodeVersion=$(cat .nvmrc | head -n 1) echo ::set-output name=nodeVersion::${nodeVersion} if [[ "${{ github.event_name }}" = "push" ]]; then envName="$(echo ${{ github.ref }} | rev | cut -d '/' -f 1 | rev)" bucketName="${{ github.event.repository.name }}-$envName" echo ::set-output name=bucketName::${bucketName} echo ::set-output name=envName::${envName} fi - name: Build and export to local Docker id: docker_build uses: docker/build-push-action@v3 with: load: true build-args: | APP=${{ matrix.app }} NODE_VERSION=${{ steps.tags.outputs.nodeVersion }} ENV_NAME=${{ steps.tags.outputs.envName || '' }} tags: | ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:local - name: Sanity check docker image run: | echo "Check ipfs-hash" docker run --rm ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:local cat ipfs-hash echo "List html directory" docker run --rm ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:local ls -lah echo "Copy dist to local filesystem" docker create --name=dist ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:local docker cp dist:/usr/share/nginx/html dist echo "Check local dist" ls -al dist - name: Publish dist as docker image uses: docker/build-push-action@v3 if: ${{ github.event_name == 'pull_request' }} with: push: true build-args: | APP=${{ matrix.app }} NODE_VERSION=${{ steps.tags.outputs.nodeVersion }} tags: | ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:${{ github.event.pull_request.head.sha || github.sha }} # - uses: shallwefootball/s3-upload-action@master # if: ${{ github.event_name == 'push' }} # name: Upload dist S3 # with: # aws_key_id: ${{ secrets.AWS_KEY_ID }} # aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}} # aws_bucket: ${{ steps.tags.outputs.bucketName }} # source_dir: 'dist' - 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 run: echo ${{ steps.docker_build.outputs.digest }}