Optimize github build workflow
This commit is contained in:
31
.github/workflows/docker-image.yml
vendored
31
.github/workflows/docker-image.yml
vendored
@@ -18,12 +18,26 @@ jobs:
|
|||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up QEMU
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-qemu-action@v3
|
||||||
with:
|
with:
|
||||||
buildkitd-flags: --debug
|
platforms: arm64
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
driver-opts: |
|
driver-opts: |
|
||||||
image=moby/buildkit:v0.12.0
|
image=moby/buildkit:master
|
||||||
|
network=host
|
||||||
|
|
||||||
|
- name: Cache npm dependencies
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
|
|
||||||
- name: Cache Docker layers
|
- name: Cache Docker layers
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
@@ -34,7 +48,7 @@ jobs:
|
|||||||
${{ runner.os }}-buildx-
|
${{ runner.os }}-buildx-
|
||||||
|
|
||||||
- name: Login to Docker Registry
|
- name: Login to Docker Registry
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
@@ -51,18 +65,21 @@ jobs:
|
|||||||
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
|
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Build and Push Multi-Arch Docker Image
|
- name: Build and Push Multi-Arch Docker Image
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./docker/Dockerfile
|
file: ./docker/Dockerfile
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
tags: ghcr.io/${{ env.REPO_OWNER }}/termix:${{ env.IMAGE_TAG }}
|
tags: ghcr.io/${{ env.REPO_OWNER }}/termix:${{ env.IMAGE_TAG }}
|
||||||
labels: org.opencontainers.image.source=https://github.com/${{ github.repository }}
|
labels: |
|
||||||
|
org.opencontainers.image.source=https://github.com/${{ github.repository }}
|
||||||
|
org.opencontainers.image.revision=${{ github.sha }}
|
||||||
cache-from: type=local,src=/tmp/.buildx-cache
|
cache-from: type=local,src=/tmp/.buildx-cache
|
||||||
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
|
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
|
||||||
build-args: |
|
build-args: |
|
||||||
BUILDKIT_INLINE_CACHE=1
|
BUILDKIT_INLINE_CACHE=1
|
||||||
|
outputs: type=registry,compression=zstd,compression-level=19
|
||||||
|
|
||||||
# Temp fix for https://github.com/docker/build-push-action/issues/252
|
# Temp fix for https://github.com/docker/build-push-action/issues/252
|
||||||
- name: Move cache
|
- name: Move cache
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
FROM --platform=$BUILDPLATFORM node:18-alpine AS frontend-builder
|
FROM --platform=$BUILDPLATFORM node:18-alpine AS frontend-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci --only=production
|
# Install all dependencies including dev dependencies needed for build
|
||||||
|
RUN npm ci
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ RUN apk add --no-cache python3 make g++ \
|
|||||||
&& rm -rf /root/.npm
|
&& rm -rf /root/.npm
|
||||||
|
|
||||||
# Stage 4: Final production image
|
# Stage 4: Final production image
|
||||||
FROM ubuntu:20.04 as base
|
FROM ubuntu:20.04-slim as base
|
||||||
|
|
||||||
# Prevent interactive prompts during package installation
|
# Prevent interactive prompts during package installation
|
||||||
ENV DEBIAN_FRONTEND=noninteractive \
|
ENV DEBIAN_FRONTEND=noninteractive \
|
||||||
@@ -47,15 +48,12 @@ RUN apt-get update && \
|
|||||||
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list && \
|
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list && \
|
||||||
# Add Node.js repo
|
# Add Node.js repo
|
||||||
wget -qO- https://deb.nodesource.com/setup_${NODE_VERSION} | bash - && \
|
wget -qO- https://deb.nodesource.com/setup_${NODE_VERSION} | bash - && \
|
||||||
# Install Node.js and MongoDB
|
# Install Node.js and MongoDB (minimal install)
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y --no-install-recommends \
|
apt-get install -y --no-install-recommends \
|
||||||
nodejs \
|
nodejs \
|
||||||
mongodb-org=${MONGO_VERSION} \
|
|
||||||
mongodb-org-server=${MONGO_VERSION} \
|
mongodb-org-server=${MONGO_VERSION} \
|
||||||
mongodb-org-shell=${MONGO_VERSION} \
|
mongodb-org-shell=${MONGO_VERSION} && \
|
||||||
mongodb-org-mongos=${MONGO_VERSION} \
|
|
||||||
mongodb-org-tools=${MONGO_VERSION} && \
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
apt-get clean && \
|
apt-get clean && \
|
||||||
rm -rf /var/lib/apt/lists/* /var/cache/apt/* /root/.npm /tmp/* && \
|
rm -rf /var/lib/apt/lists/* /var/cache/apt/* /root/.npm /tmp/* && \
|
||||||
|
|||||||
Reference in New Issue
Block a user