agones.dev/agones@v1.54.0/build/build-image/cache/cloudbuild.yaml (about)

     1  ---
     2  # Copyright 2023 Google LLC
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  steps:
    17  
    18    #
    19    # Move everything to the /workspace as this is what the canonical
    20    # build script uses, and we want to be as close to that as possible.
    21    #
    22    - name: bash
    23      id: setup-cache-files
    24      script: |
    25        mkdir /tmp/workspace && \
    26        mv /workspace/* /tmp/workspace && \
    27        mv /tmp/workspace/build/build-image/cache/* . && \
    28        ls -l
    29  
    30    - name: 'gcr.io/cloud-builders/docker'
    31      id: build_base_image
    32      args:
    33        - 'build'
    34        - '--tag=us-docker.pkg.dev/$PROJECT_ID/ci/cache:${_VERSION}'
    35        - '--tag=us-docker.pkg.dev/$PROJECT_ID/ci/cache:latest'
    36        - '--file=Dockerfile-base'
    37        - '.'
    38  
    39    - name: 'gcr.io/cloud-builders/docker'
    40      id: build_save_cache
    41      args:
    42        - 'build'
    43        - '--tag=us-docker.pkg.dev/$PROJECT_ID/ci/save_cache:${_VERSION}'
    44        - '--tag=us-docker.pkg.dev/$PROJECT_ID/ci/save_cache:latest'
    45        - '--file=Dockerfile-save'
    46        - '--build-arg=project_id=$PROJECT_ID'
    47        - '--cache-from=us-docker.pkg.dev/$PROJECT_ID/ci/cache:latest'
    48        - '.'
    49  
    50    - name: 'gcr.io/cloud-builders/docker'
    51      id: build_restore_cache
    52      args:
    53        - 'build'
    54        - '--tag=us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache:${_VERSION}'
    55        - '--tag=us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache:latest'
    56        - '--file=Dockerfile-restore'
    57        - '--build-arg=project_id=$PROJECT_ID'
    58        - '--cache-from=us-docker.pkg.dev/$PROJECT_ID/ci/cache:latest'
    59        - '.'
    60  
    61    # Test the script
    62    - name: 'gcr.io/cloud-builders/gsutil'
    63      id: setup_test
    64      entrypoint: 'bash'
    65      args:
    66        - '-c'
    67        - |
    68          echo "Creating test cache file structure."
    69          mkdir -p /original/folder1 /original/folder2/subfolder3 rel_folder
    70          touch /original/folder1/file1.txt
    71          touch /original/folder1/file2.txt
    72          touch /original/folder2/ignore.txt
    73          touch /original/folder2/subfolder3/file1.txt
    74          touch rel_folder/file3.txt
    75      volumes:
    76        - name: original
    77          path: /original
    78  
    79    - name: 'us-docker.pkg.dev/$PROJECT_ID/ci/save_cache'
    80      id: save_cache
    81      args:
    82        - '--out=/cached'
    83        - '--key=simple-key-$( checksum cloudbuild.yaml )'
    84        - '--path=/original/folder1'
    85        - '--path=/original/folder2/subfolder3'
    86        - '--path=rel_folder'
    87      volumes:
    88        - name: original
    89          path: /original
    90        - name: cached
    91          path: /cached
    92  
    93    - name: 'us-docker.pkg.dev/$PROJECT_ID/ci/save_cache'
    94      id: verify_cache
    95      entrypoint: 'bash'
    96      args:
    97        - '-c'
    98        - |
    99          echo "Verifying cache file exists."
   100          cache_file="/cached/simple-key-$( checksum cloudbuild.yaml ).tgz"
   101          if [[ ! -f "${cache_file}" ]];then
   102            echo "Missing cache file at ${cache_file}"
   103            echo "Contents:"
   104            echo "$(ls -al /cached)"
   105            exit 1
   106          fi
   107          echo "Cache tests passed."
   108      volumes:
   109        - name: cached
   110          path: /cached
   111  
   112    - name: 'gcr.io/cloud-builders/gsutil'
   113      id: clean_cache
   114      entrypoint: bash
   115      args:
   116        - -c
   117        - |
   118          echo "Clearing original files..."
   119          rm -rf /original/*
   120          rm -rf rel_folder/
   121      volumes:
   122        - name: original
   123          path: /original
   124  
   125    - name: 'us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache'
   126      id: restore_cache
   127      args:
   128        - '--src=/cached'
   129        - '--key=simple-key-$( checksum cloudbuild.yaml )'
   130      volumes:
   131        - name: original
   132          path: /original
   133        - name: cached
   134          path: /cached
   135  
   136    - name: 'gcr.io/cloud-builders/gsutil'
   137      id: verify_restore
   138      entrypoint: bash
   139      args:
   140        - '-c'
   141        - |
   142          test -f /original/folder1/file1.txt
   143          test -f /original/folder1/file2.txt
   144          test -f /original/folder2/ignore.txt
   145          test -f /original/folder2/subfolder3/file1.txt
   146          test -f rel_folder/file3.txt
   147          test -f /workspace/rel_folder/file3.txt
   148      volumes:
   149        - name: original
   150          path: /original
   151  
   152  substitutions:
   153    _VERSION: '1.2'
   154  
   155  images:
   156    - 'us-docker.pkg.dev/$PROJECT_ID/ci/cache:${_VERSION}'
   157    - 'us-docker.pkg.dev/$PROJECT_ID/ci/cache:latest'
   158    - 'us-docker.pkg.dev/$PROJECT_ID/ci/save_cache:${_VERSION}'
   159    - 'us-docker.pkg.dev/$PROJECT_ID/ci/save_cache:latest'
   160    - 'us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache:${_VERSION}'
   161    - 'us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache:latest'