diff --git a/.github/workflows/build-dev.yaml b/.github/workflows/build-image.yaml similarity index 76% rename from .github/workflows/build-dev.yaml rename to .github/workflows/build-image.yaml index 35426aaf..07cbd73b 100644 --- a/.github/workflows/build-dev.yaml +++ b/.github/workflows/build-image.yaml @@ -1,8 +1,10 @@ -name: Build Development +name: Build image on: push: branches: ["main"] + tags: + - v[0-9]+.[0-9]+.[0-9]+ # Semver Release (non-prerelease) pull_request: branches: [main] @@ -19,15 +21,20 @@ jobs: uses: docker/metadata-action@v4 with: images: hub.opensciencegrid.org/macrostrat/web + # New: apply the 'latest' tag to non-prerelease semver tags tags: | - type=semver,pattern={{version}} + type=raw,value=sha-{{sha}} type=raw,value=latest-itb + type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-')}} + type=raw,value=latest-itb-{{date 'YYYYMMDDHHmmss'}} type=ref,event=pr,suffix=-{{date 'YYYYMMDDHHmmss'}} type=ref,event=branch,suffix=-{{date 'YYYYMMDDHHmmss'}} type=ref,event=tag,suffix=-{{date 'YYYYMMDDHHmmss'}} - type=raw,value=latest-itb-{{date 'YYYYMMDDHHmmss'}} - type=raw,value=sha-{{sha}} - - name: Set up Docker Buildx + type=semver,pattern={{version}} + type=semver,pattern={{version}}-{{date 'YYYYMMDDHHmmss'}} + flavor: | + latest=false + - name: Set up Docker BuildX uses: docker/setup-buildx-action@v2 - name: Login to OSG DockerHub uses: docker/login-action@v2 diff --git a/.github/workflows/build-prod.yaml b/.github/workflows/build-prod.yaml deleted file mode 100644 index e77f6127..00000000 --- a/.github/workflows/build-prod.yaml +++ /dev/null @@ -1,43 +0,0 @@ -name: Build Production - -on: - push: - tags: - - v[0-9]+.[0-9]+.[0-9]+ # Semver Release - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: "recursive" - - name: Docker meta - id: meta - uses: docker/metadata-action@v4 - with: - images: hub.opensciencegrid.org/macrostrat/web - tags: | - type=ref,event=pr,suffix=-{{date 'YYYYMMDDHHmmss'}} - type=ref,event=branch,suffix=-{{date 'YYYYMMDDHHmmss'}} - type=semver,pattern={{version}} - type=raw,value=latest,enable={{is_default_branch}} - type=raw,value=sha-{{sha}} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Login to OSG DockerHub - uses: docker/login-action@v2 - with: - registry: hub.opensciencegrid.org - username: ${{ vars.HARBOR_CLI_NAME }} - password: ${{ secrets.HARBOR_CLI_SECRET }} - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/.github/workflows/test-build.yaml b/.github/workflows/test-build.yaml deleted file mode 100644 index 9aaa1c77..00000000 --- a/.github/workflows/test-build.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: Test Website Build - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - test-build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: "recursive" - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "npm" - - run: yarn install - - run: yarn build diff --git a/Dockerfile b/Dockerfile index 5342ec36..d852a8aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,14 +6,38 @@ RUN apt-get update && apt-get install -y rsync ENV NODE_ENV=production WORKDIR /usr/src/app -COPY . ./ +COPY .yarn/releases .yarn/releases +COPY .yarnrc.yml yarn.lock package.json ./ + +# Copy only the elements needed for a Yarn install to take advantage of +# Docker's layer caching +# This is complex because we are working with multiple workspaces. + +# Copy package JSON files with wildcards +# This scoops up all package.json files in the directory and subdirectories +# to deal with Yarn workspaces. However it requires BUILDKIT to be enabled, +# which is done by setting DOCKER_BUILDKIT=1 in the environment +RUN --mount=type=bind,target=/docker-context \ + cd /docker-context/; \ + find . -name "package.json" -mindepth 0 -maxdepth 5 -exec cp --parents "{}" /usr/src/app/ \; + +RUN yarn install --immutable # Load the cache from the previous build RUN --mount=type=cache,target=/yarn-cache \ - rsync -a /yarn-cache/ .yarn/cache \ + rsync -a /yarn-cache/ .yarn/cache/ \ && yarn install --immutable \ && rsync -a .yarn/cache/ /yarn-cache +# # Remove rsync +RUN apt-get remove -y rsync + +# # Now we can run the full copy command + +COPY . ./ + +ENV NODE_ENV=production + RUN yarn run build EXPOSE 3000