Skip to content

Commit

Permalink
ci: use multi-environment docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiendan committed Aug 14, 2023
1 parent a73811e commit 2007133
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 44 deletions.
95 changes: 53 additions & 42 deletions .github/workflows/docker_build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: Docker_build_push
on:
release:
types: [created]
workflow_dispatch:

env:
REGISTRY: ghcr.io
Expand All @@ -12,46 +11,58 @@ env:
jobs:
docker:
name: Build and push docker image to GitHub Container Registry
strategy:
matrix:
environment: [devnet-1]
runs-on: ubuntu-latest-16-core
environment: ${{ matrix.environment }}
outputs:
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
short-length: 7

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=raw,value=test,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Push to GitHub Container Registry
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:build-cache-${{ env.GITHUB_REF_SLUG_URL }}-${{ github.workflow }}
type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:build-cache-main-${{ github.workflow }}
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:build-cache-${{ env.GITHUB_REF_SLUG_URL }}-${{ github.workflow }},mode=max
- name: Checkout
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
short-length: 7

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}-{{ matrix.environment }}
type=semver,pattern={{major}}.{{minor}}-{{ matrix.environment }}
- name: Push to GitHub Container Registry
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VITE_EXECUTOR_SERVICE_ENDPOINT=${{ vars.VITE_EXECUTOR_SERVICE_ENDPOINT }}
VITE_SUBNET_REGISTRATOR_CONTRACT_ADDRESS=${{ vars.VITE_SUBNET_REGISTRATOR_CONTRACT_ADDRESS }}
VITE_ERC20_MESSAGING_CONTRACT_ADDRESS=${{ vars.VITE_ERC20_MESSAGING_CONTRACT_ADDRESS }}
VITE_TOPOS_CORE_PROXY_CONTRACT_ADDRESS=${{ vars.VITE_TOPOS_CORE_PROXY_CONTRACT_ADDRESS }}
VITE_TOPOS_SUBNET_ENDPOINT=${{ vars.VITE_TOPOS_SUBNET_ENDPOINT }}
VITE_TRACING_OTEL_COLLECTOR_ENDPOINT=${{ vars.VITE_TRACING_OTEL_COLLECTOR_ENDPOINT }}
VITE_TRACING_SERVICE_NAME=${{ vars.VITE_TRACING_SERVICE_NAME }}
VITE_TRACING_SERVICE_VERSION=${{ vars.VITE_TRACING_SERVICE_VERSION }}
cache-from: |
type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:build-cache-${{ env.GITHUB_REF_SLUG_URL }}-${{ github.workflow }}
type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:build-cache-main-${{ github.workflow }}
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:build-cache-${{ env.GITHUB_REF_SLUG_URL }}-${{ github.workflow }},mode=max
11 changes: 9 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
FROM node:lts-alpine

ARG VITE_EXECUTOR_SERVICE_ENDPOINT
ARG VITE_SUBNET_REGISTRATOR_CONTRACT_ADDRESS
ARG VITE_ERC20_MESSAGING_CONTRACT_ADDRESS
ARG VITE_TOPOS_CORE_PROXY_CONTRACT_ADDRESS
ARG VITE_TOPOS_SUBNET_ENDPOINT
ARG VITE_TRACING_OTEL_COLLECTOR_ENDPOINT
ARG VITE_TRACING_SERVICE_NAME
ARG VITE_TRACING_SERVICE_VERSION

WORKDIR /usr/src/app

COPY package*.json ./
Expand All @@ -13,6 +22,4 @@ COPY . ./

RUN npm run frontend:build

RUN npm run backend:build

CMD npm run backend:start:prod

0 comments on commit 2007133

Please sign in to comment.