Score:0

GCP Function Deployment : Zip file from local build but not Zip File from Github Action

ru flag

I am trying to have a github action that build a zip file with code function source code and upload it to Google Cloud Storage

Then I have a terraform repository that deploy cloud function using this zip file.

The thing is that when I zip those file on my local environnement - WSL Ubuntu 18-04 - and I upload the zip into the same storage I can proceed with my terraform deployment and everything goes fine.

zip ../0.0.9.zip *

However the same command executed from Github Action create a zip, push it to a Cloud Storage as expected, I can also download it and open it but the Cloud Build process for Cloud Function Deployment doesn't work. I can not figure what's the difference between thoses.

Here is the Github Action workflow :

name: Function Deploy

on:
  push:
    tags:
      - '*'

jobs:
  build:
    name: 'Build & Push'
    runs-on: ubuntu-latest

    defaults:
      run:
        shell: bash

    steps:
    - name: Checkout
      uses: actions/checkout@v3

    - name: Using Node
      uses: actions/setup-node@v2
      with:
        node-version: "16.x"

    - name: Installing Node Modules
      run: npm install

    - name: Building
      run: npm run build

    - name: Copy files
      run: |
        cp package.json ./lib/package.json
        cp package-lock.json ./lib/package-lock.json
        cp cloudbuild.yaml ./lib/cloudbuild.yaml

    - name: Zipping Version
      run: |
        cd lib
        zip ../${{ github.ref_name }}.zip *
        cd ..

    - name: Auth to GCP
      uses: google-github-actions/auth@v1
      with:
        credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}
    - name: Uploading
      uses: google-github-actions/upload-cloud-storage@v1
      with:
        path: ${{ github.ref_name }}.zip
        destination: ${{ secrets.GCP_BUCKET_NAME }}

and here is the error log from cloud build :

starting build "ac767a2c-5242-4315-8b20-f8672206b04c"
FETCHSOURCE
Fetching storage object: gs://gcf-sources-xxxxx-europe-west1/ln-func-bcareer-e8268533-f38c-44a7-b62e-ec74a3affe0b/version-2/function-source.zip#1669544086773073
Copying gs://gcf-sources-xxxxxx-europe-west1/ln-func-bcareer-e8268533-f38c-44a7-b62e-ec74a3affe0b/version-2/function-source.zip#1669544086773073...
/ [0 files][ 0.0 B/ 31.6 KiB] / [1 files][ 31.6 KiB/ 31.6 KiB]
Operation completed over 1 objects/31.6 KiB.
Archive: /tmp/source-archive.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of /tmp/source-archive.zip or
/tmp/source-archive.zip.zip, and cannot find /tmp/source-archive.zip.ZIP, period.

The zip command used is the same, in the same version in both process.

The zip file generated by Github Action can be downloaded from cloud storage and opened fine in Windows :

enter image description here

But when fetched on Build Storage it can not be opened anymore :

enter image description here

while again, the zip produce from my local can also be download and open from cloud build storage

What did I miss ?

Score:0
ru flag

So it seems that actually my issue was into the upload of the file and not the zipping of it.

I've missed this part in the documentation of the upload action saying that by default encoding is set as gzip.

enter image description here

Removing it did the trick

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.