Skip to content

build-and-deploy-images #230

build-and-deploy-images

build-and-deploy-images #230

name: build-and-deploy-images
on:
workflow_run:
types:
- completed
branches: [master]
workflows: [update-shrinkwrap-and-test]
concurrency:
group: build-and-upload-images
cancel-in-progress: true
env:
REGISTRY: harbor.jamezrin.name
BROWSERSLIST_IGNORE_OLD_DATA: "1"
jobs:
build-packages:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: true
matrix:
node-version: [16.x]
platform: ['amd64', 'arm64']
package: ['frontend', 'backend']
include:
- platform: amd64
runner: ubuntu-latest
- platform: arm64
runner: self-hosted
- package: frontend
deploy: false
- package: backend
deploy: true
steps:
- uses: actions/checkout@v3
- name: Login to my Registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
- name: Create docker context
run: docker context create builders
- uses: docker/setup-buildx-action@v1
with:
buildkitd-flags: --debug
endpoint: builders
- name: Compute image variables
id: compute_vars
run: |
version=$(jq -r .version ./apps/${{ matrix.package }}/package.json)
image_name="${{ env.REGISTRY }}/library/timeit-${{ matrix.package }}"
full_image_tag="${image_name}:${version}-${{ matrix.platform }}"
echo "::set-output name=full_image_tag::${full_image_tag}"
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install rush and pnpm
run: npm install -g @microsoft/rush pnpm
- name: Install dependencies
run: rush install --to @timeit/${{ matrix.package }} --purge
- name: Build package
run: rush build --to @timeit/${{ matrix.package }}
- name: Deploy package
if: ${{ matrix.deploy }}
run: rush deploy -p @timeit/${{ matrix.package }} --overwrite
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
file: ./apps/${{ matrix.package }}/Dockerfile
tags: ${{ steps.compute_vars.outputs.full_image_tag }}
create-manifest:
runs-on: ubuntu-latest
needs: [build-packages]
strategy:
fail-fast: true
matrix:
package: ['frontend', 'backend']
steps:
- uses: actions/checkout@v3
- name: Login to my Registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
- name: Build manifests
run: |
version=$(jq -r .version ./apps/${{ matrix.package }}/package.json)
image_name="${{ env.REGISTRY }}/library/timeit-${{ matrix.package }}"
echo "Creating manifest for ${version} tag"
docker buildx imagetools create -t ${image_name}:${version} \
${image_name}:${version}-amd64 \
${image_name}:${version}-arm64
echo "Re-tagging latest"
docker buildx imagetools create -t ${image_name}:latest \
${image_name}:${version}