build-and-deploy-images #254
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-ingress-tailscale.tail11c31.ts.net | |
BROWSERSLIST_IGNORE_OLD_DATA: "1" | |
jobs: | |
build-packages: | |
runs-on: ${{ matrix.runner }} | |
strategy: | |
fail-fast: true | |
matrix: | |
node-version: [22.x] | |
platform: ['amd64', 'arm64'] | |
package: ['frontend', 'backend'] | |
include: | |
- platform: amd64 | |
runner: ubuntu-latest | |
- platform: arm64 | |
runner: arc-runner-timeit-webapp | |
- package: frontend | |
deploy: false | |
- package: backend | |
deploy: true | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Tailscale | |
uses: tailscale/github-action@v2 | |
with: | |
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} | |
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} | |
tags: tag:ci | |
# Workaround for https://github.com/tailscale/github-action/issues/108 | |
- name: Build DNS resolutions | |
id: build_hosts_resolutions | |
run: | | |
registry_ip=$(sudo dig +short ${{ env.REGISTRY }}) | |
echo "hosts=${{ env.REGISTRY }}:$registry_ip" >> "$GITHUB_OUTPUT" | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: | | |
network=host | |
buildkitd-config-inline: | | |
[dns] | |
nameservers=["100.100.100.100"] | |
- name: Login to registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} | |
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} | |
- 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: . | |
add-hosts: ${{ steps.build_hosts_resolutions.outputs.hosts }} | |
file: ./apps/${{ matrix.package }}/Dockerfile | |
push: true | |
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: Tailscale | |
uses: tailscale/github-action@v2 | |
with: | |
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} | |
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} | |
tags: tag:ci | |
# Workaround for https://github.com/tailscale/github-action/issues/108 | |
- name: Build DNS resolutions | |
id: build_hosts_resolutions | |
run: | | |
registry_ip=$(sudo dig +short ${{ env.REGISTRY }}) | |
echo "hosts=${{ env.REGISTRY }}:$registry_ip" >> "$GITHUB_OUTPUT" | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: | | |
network=host | |
buildkitd-config-inline: | | |
[dns] | |
nameservers=["100.100.100.100"] | |
- name: Login to registry | |
uses: docker/login-action@v3 | |
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} |