From 683c52ae6226feb5ce908ed1632e0ccb67e484b9 Mon Sep 17 00:00:00 2001 From: Toby Bellwood Date: Tue, 9 Jul 2024 18:23:51 +1000 Subject: [PATCH] build: small refactor --- .github/workflows/docker-image.yaml | 19 +++++++++++++ Dockerfile | 6 ++--- docker-compose.local-dev.yaml | 27 +++++++++++++++++++ docker-compose.yml | 41 ++++------------------------- 4 files changed, 54 insertions(+), 39 deletions(-) create mode 100644 docker-compose.local-dev.yaml diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml index 4bc52b33..7134068f 100644 --- a/.github/workflows/docker-image.yaml +++ b/.github/workflows/docker-image.yaml @@ -90,6 +90,23 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - + name: Cache + uses: actions/cache@v3 + id: cache + with: + path: | + yarn-cache + key: cache-${{ hashFiles('**/yarn.lock') }} + - + name: inject cache into docker + uses: reproducible-containers/buildkit-cache-dance@v3.1.0 + with: + cache-map: | + { + "yarn-cache": "/home/.yarn" + } + skip-extraction: ${{ steps.cache.outputs.cache-hit }} - name: Build and push uses: docker/build-push-action@v5 @@ -99,6 +116,8 @@ jobs: build-args: | "LAGOON_VERSION=${{ env.VERSION }}" "BUILD=${{ env.BUILD }}" + cache-from: type=gha + cache-to: type=gha,mode=max push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 7506a68d..e6efb44b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Node builder image -FROM uselagoon/node-20-builder:latest AS dev +FROM uselagoon/node-20-builder:latest AS local-dev # Copy only what we need into the image COPY ./src/ /app/src @@ -27,7 +27,7 @@ ENV KEYCLOAK_API=$KEYCLOAK_API FROM uselagoon/node-20:latest AS prod-builder # Copy the whole /app folder from dev -COPY --from=dev /app/ /app/ +COPY --from=local-dev /app/ /app/ # Build app RUN --mount=type=cache,target=/home/.yarn YARN_CACHE_FOLDER=/home/.yarn yarn run build @@ -35,7 +35,7 @@ RUN --mount=type=cache,target=/home/.yarn YARN_CACHE_FOLDER=/home/.yarn yarn run RUN --mount=type=cache,target=/home/.yarn YARN_CACHE_FOLDER=/home/.yarn yarn workspaces focus -A --production # Build the final production image -FROM uselagoon/node-20:latest +FROM uselagoon/node-20:latest AS prod # Copy the whole /app folder from prod-builder COPY --from=prod-builder /app/ /app/ diff --git a/docker-compose.local-dev.yaml b/docker-compose.local-dev.yaml new file mode 100644 index 00000000..eeda6fb5 --- /dev/null +++ b/docker-compose.local-dev.yaml @@ -0,0 +1,27 @@ +version: '3.2' + +services: + ui: + build: + context: . + target: local-dev + dockerfile: Dockerfile + labels: + lagoon.type: none + command: yarn run dev + volumes: + - ./src:/app/src + - ./.env.defaults:/app/.env.defaults + - ./.env.schema:/app/.env.schema + - ./package.json:/app/package.json + ports: + - '3003:3003' + networks: + - default + environment: + LAGOON_ROUTE: http://lagoon-ui.docker.amazee.io + LAGOON_UI_TOURS_ENABLED: true + NODE_ENV: development + GRAPHQL_API: "${GRAPHQL_API:-http://0.0.0.0:3000/graphql}" + KEYCLOAK_API: "${KEYCLOAK_API:-http://0.0.0.0:8088/auth}" + diff --git a/docker-compose.yml b/docker-compose.yml index 95e4c4d6..3a3407a4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,18 +1,10 @@ version: '3.2' -x-lagoon-project: - # Lagoon project name (leave `&lagoon-project` when you edit this) - &lagoon-project lagoon-ui - -x-environment: &default-environment - LAGOON_PROJECT: *lagoon-project - GRAPHQL_API: "${GRAPHQL_API:-http://0.0.0.0:3000/graphql}" - KEYCLOAK_API: "${KEYCLOAK_API:-http://0.0.0.0:8088/auth}" - services: ui: build: context: . + target: prod dockerfile: Dockerfile labels: lagoon.type: node @@ -22,31 +14,8 @@ services: networks: - default environment: - LAGOON_ROUTE: &default-url http://lagoon-ui.docker.amazee.io + LAGOON_ROUTE: http://lagoon-ui.docker.amazee.io LAGOON_UI_TOURS_ENABLED: false - LAGOON_ENVIRONMENT_TYPE: production - <<: *default-environment - - dev: - build: - context: . - target: dev - dockerfile: Dockerfile - labels: - lagoon.type: none - command: yarn run dev - volumes: - - ./src:/app/src - - ./.env.defaults:/app/.env.defaults - - ./.env.schema:/app/.env.schema - - ./package.json:/app/package.json - ports: - - '3003:3003' - networks: - - default - environment: - LAGOON_ROUTE: http://lagoon-dev.docker.amazee.io - LAGOON_UI_TOURS_ENABLED: true - LAGOON_ENVIRONMENT_TYPE: development - <<: *default-environment - + NODE_ENV: production + GRAPHQL_API: "${GRAPHQL_API:-https://api.lagoon.amazeeio.cloud/graphql}" + KEYCLOAK_API: "${KEYCLOAK_API:-https://keycloak.amazeeio.cloud/auth}"