Next.js - ERROR Build directory is not writeable on Google Cloud Build - next.js

I was trying to automate the deployment process of my Next.JS application to App Engine using Cloud Build but at the build phase it keeps on failing with:
Error: > Build directory is not writeable. https://err.sh/vercel/next.js/build-dir-not-writeable
I cant seem to figure out what to fix for this.
My current build file is and it keeps failing on step 2:
steps:
# install dependencies
- name: 'gcr.io/cloud-builders/npm'
args: ['install']
# build the container image
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'build']
# deploy to app engine
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy"]
env:
- 'PORT=8080'
- 'NODE_ENV=production'
timeout: "1600s"
app.yaml:
runtime: nodejs12
handlers:
- url: /.*
secure: always
script: auto
env_variables:
PORT: 8080
NODE_ENV: 'production'
any help would be appreciated

Can reproduce the same behavior after upgrading to next version 9.3.3.
Cause
The issue is related to the npm dependency which is managed by google if you use gcr.io/cloud-builders/npm seems they are running your build inside of Google Cloud Build on an old node version.
Here you can find the currently supported version
https://console.cloud.google.com/gcr/images/cloud-builders/GLOBAL/npm?gcrImageListsize=30
As you can see Googles latest node version is 10.10. The newest next.js version requires at least node 10.13
Solution
Change gcr.io/cloud-builders/npm to
- name: node
entrypoint: npm
in order to use the official docker npm package which runs on node12.
After those changes your build will be successful again.
Sidenote
Switching to the official npm will increase the build duration (at least in my case). It takes around 2 minutes longer then the gcr npm.

Related

Github Actions - How can I make my env variable(stored in .env file) available in my workflow

I'll try to be as clear as possible. I have also asked about related issues but didn't receive a convincing response.
I'm using React and firebase for hosting.
Also, I'm storing my firebase web API key in my .env file.
I set up firebase hosting using Firebase CLI and chose to automatically deploy on merge or pull request.
After the setup finished a .github folder with .yml file was created in my working directory.
.github
- workflows
-firebase-hosting-merge.yml
-firebase-hosting-pull-request.yml
So now when I deploy my project(without pushing to GitHub) manually to firebase by running firebase deploy everything works fine and my app is up and running.
However when I make changes and push my changes to Github. Github actions are triggered and the automatic deployment to the firebase process starts. The build passes all the checks. However, when I visit the hosted URL there is an error I get in the console saying Your API key is invalid, please check you have copied it correctly.
I tried few workarounds like storing my firebase web API key into the Github secrets and accessing it in my .yml file.
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools
name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- master
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- run: npm ci && npm run build --prod
- uses: FirebaseExtended/action-hosting-deploy#v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_EVENTS_EASY }}'
channelId: live
projectId: my-project
env:
REACT_APP_API_KEY: ${{secrets.REACT_APP_API_KEY}}
FIREBASE_CLI_PREVIEWS: hostingchannels
But I am still getting the error. I feel that the error is definitely due to the environment variables.
I have stored my firebase web API key in my .env.production file located in the root directory.
Somehow GitHub actions are not using my environment variables defined.
Please let me know how can I manage my env variables so that it can be accessed by my workflow.
The answer is put custom env vars in first level before jobs:
name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- master
env: # <--- here
REACT_APP_API_KEY: ${{secrets.REACT_APP_API_KEY}} # <--- here
jobs:
build_and_deploy:
...
And add this secrets in Github > Your project > Settings > Secrets
You can use Create Envfile Github Action to create a .env file in your workflow.
To add a key to the envfile, add a key/pair to the with: section. It must begin with envkey_.
steps:
- uses: actions/checkout#v2
- name: Use Node.js
uses: actions/setup-node#v1
- name: Make envfile
uses: SpicyPizza/create-envfile#v1
with:
envkey_REACT_APP_API_KEY: ${{secrets.REACT_APP_API_KEY}}
directory: './'
file_name: '.env'

Github Actions - Workflow failure due to unexpected error, possibly due to build matrix configurations?

I am running a Github Actions workflow, where one of the task to be executed in the CI workflow is a headless gui Javafx test using testfx and monocle. I am not using Travis CI nor Appveyor.
I have no issues running it locally on my windows, and the gui tests works fine. However, when I push to my repository, the same gui test will fail due to an error.
WARNING: An illegal reflective access operation has occurred
> Task :test
WARNING: Illegal reflective access by org.testfx.toolkit.impl.ApplicationLauncherImpl (file:/home/runner/.gradle/caches/modules-2/files-2.1/org.testfx/testfx-core/4.0.16-alpha/12d7481c9326282f1023bfae9b0f96d91738af96/testfx-core-4.0.16-alpha.jar) to field com.sun.glass.ui.PlatformFactory.instance
WARNING: Please consider reporting this to the maintainers of org.testfx.toolkit.impl.ApplicationLauncherImpl
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
seedu.address.ui.WidgetViewBoxTest > update_matchingContent(FxRobot) FAILED
java.lang.RuntimeException
Caused by: java.util.concurrent.ExecutionException
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.AbstractMethodError at WidgetViewBoxTest.java:77
java.lang.AbstractMethodError: Receiver class com.sun.glass.ui.monocle.MonocleTimer does not define or inherit an implementation of the resolved method 'abstract void _pause(long)' of abstract class com.sun.glass.ui.Timer.
at javafx.graphics/com.sun.glass.ui.Timer.pause(Timer.java:143)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pauseTimer(QuantumToolkit.java:502)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.postPulse(QuantumToolkit.java:489)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$12(QuantumToolkit.java:345)
at com.sun.glass.ui.monocle.MonocleTimer$1.run(MonocleTimer.java:58)
at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
at java.base/java.util.TimerThread.run(Timer.java:506)
This is my YAML file configs for the CI.
name: Java CI
on: [push, pull_request]
jobs:
build:
strategy:
matrix:
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up repository
uses: actions/checkout#master
- name: Set up repository
uses: actions/checkout#master
with:
ref: master
- name: Merge to master
run: git checkout --progress --force ${{ github.sha }}
- name: Run repository-wide tests
if: runner.os == 'Linux'
working-directory: ${{ github.workspace }}/.github
run: ./run-checks.sh
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action#v1
- name: Setup JDK 11
uses: actions/setup-java#v1
with:
java-version: '11'
java-package: jdk+fx
- name: Setup headless system
run: ./gradlew headless
- name: Build and check with Gradle
run: ./gradlew check coverage
- uses: codecov/codecov-action#v1
if: runner.os == 'Linux'
with:
file: ${{ github.workspace }}/build/reports/jacoco/coverage/coverage.xml
fail_ci_if_error: false
It fails at Build and check with Gradle. I suspect something is not right with the build matrix setup for the jobs but I am not sure what is causing it.
What openjfx-monocle version dependency do you have declared in your pom.xml? I did a quick look and the missing _pause(long) method has been implemented in the latest version (v12.0.1+2). Plase try to update openjfx-monocle to that version and check if it resolves the issue.

Github actions replacing firebase json in flutter project

I'm running a Github action that automatically builds and releases a flutter project. But we use a dev and a production Firebase environment. so before the build I'd like to switch out the google-services.json from the dev to the production version. But I can't seem to find an easy way to do this. Or is there a better way to work with dev and production versions of Firebase inside flutter?
probably not very useful but here's the action in it's current state
on:
push:
branches: [ stable ]
name: Build and Release
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#master
with:
fetch-depth: '0'
- name: Bump version and push tag
id: tag
uses: anothrNick/github-tag-action#1.17.2
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
WITH_V: true
RELEASE_BRANCHES: stable
- uses: actions/checkout#v1
- uses: actions/setup-java#v1
with:
java-version: '12.x'
- uses: subosito/flutter-action#v1
with:
flutter-version: '1.17.3'
- run: flutter pub get
- run: flutter build appbundle
- name: Create a Release APK
uses: ncipollo/release-action#v1
with:
artifacts: "build/app/outputs/bundle/release/*.aab"
tag: ${{ steps.tag.outputs.tag }}
token: ${{ secrets.TOKEN }}
I'm very, very new to github actions and CI in general. any constructive feedback is always welcome!
Not sure that's the most optimised solution but it's what I found being the easiest to update and maintain.
Step 1 : Store the google-services.json files in the secrets of your Github repository (that way you won't have to commit this file in your repo, that's a bonus) with names like FIREBASE_CONFIG_DEV and FIREBASE_CONFIG_PROD.
Step 2 : Create two workflows : one for the dev, triggered every pull-request for example, and the other one for the release, triggered by a commit on a specific branch like your did
Step 3 : Provide the google-service.json to your project
steps:
- uses: actions/checkout#v1
- name: Provide Firebase Android
env:
FIREBASE_CONFIG_DEV: ${{ secrets.FIREBASE_CONFIG_DEV }}
run: echo $FIREBASE_CONFIG_DEV > ./android/app/google-services.json
Your Dev workflow should look like this
Just edit this snippet to add the creation of the google-services.json to your iOS project and you should be good to go

How can I set up a Bitbucket and SonarCloud integration for a Xamarin.Forms project?

Disclaimer: I do have almost no knowledge with DevOps, containers and CI/CD pipelines and it's something I'm learning on the fly.
I currently have a private Xamarin.Forms project hosted on Bitbucket, and I've created a SonarCloud account that I want to use to analyze the code within Bitbucket. From what I was able to gather from the SonarCloud onboarding process I need to setup a build pipeline within Bitbucket.
This is a code snippet of what SonarCloud says that I need to use within the bitbucket-pipelines.yml file:
image: ************************** # Choose an image matching your project needs
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:
- step: &build-test-sonarcloud
name: Build, test and analyze on SonarCloud
caches:
- ************************** # See https://confluence.atlassian.com/bitbucket/caching-dependencies-895552876.html
- sonar
script:
- ************************** # Build your project and run
- pipe: sonarsource/sonarcloud-scan:1.0.1
- step: &check-quality-gate-sonarcloud
name: Check the Quality Gate on SonarCloud
script:
- pipe: sonarsource/sonarcloud-quality-gate:0.1.3
pipelines: # More info here: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
branches:
master:
- step: *build-test-sonarcloud
- step: *check-quality-gate-sonarcloud
pull-requests:
'**':
- step: *build-test-sonarcloud
- step: *check-quality-gate-sonarcloud
I've read and re-read the https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html article, but I wasn't ablet to gather much information. Seems like a rabbit hole with links to another articles that don't seem like they will be able to get me where I need.
So, a the moment my major doubts are:
Can a Bitbucket pipeline build Xamarin.Forms projects? (Android and iOS)
If so, how can I set up a bitbucket-pipelines.yml in order to allow that?
If not, should I go to Azure Devops or some other platform that will allow me to do that and integrate with SonarCloud?
I'm already using Visual Studio App Center to build the Android and iOS app (integraged with Bitbucket). But it seems like the AppCenter can't be natively integrated with SonarCloud.
Can anyone help me with that?
Attaching a sample working bitbucket-pipelines.yml file for reference
image: node:10.15.0 # Choose an image matching your project needs
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:
- step: &build-test-sonarcloud
name: Build, test and analyze on SonarCloud
caches:
- node # See https://confluence.atlassian.com/bitbucket/caching-dependencies-895552876.html
- sonar
script:
- npm install
- pipe: sonarsource/sonarcloud-scan:1.2.0
- step: &check-quality-gate-sonarcloud
name: Check the Quality Gate on SonarCloud
script:
- pipe: sonarsource/sonarcloud-quality-gate:0.1.4
pipelines: # More info here: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
custom: # defines that this can only be triggered manually or by a schedule
staging: # The name that is displayed in the list in the Bitbucket Cloud GUI
- step:
script:
- echo "Scheduled builds in Pipelines are awesome!"
- step:
name: Build, test and analyze on SonarCloud
caches:
- node # See https://confluence.atlassian.com/bitbucket/caching-dependencies-895552876.html
- sonar
script:
- pipe: sonarsource/sonarcloud-scan:1.2.0
- step: &check-quality-gate-sonarcloud
name: Check the Quality Gate on SonarCloud
script:
- pipe: sonarsource/sonarcloud-quality-gate:0.1.4
branches:
master:
- step: *build-test-sonarcloud
- step: *check-quality-gate-sonarcloud
pull-requests:
'**':
- step: *build-test-sonarcloud
- step: *check-quality-gate-sonarcloud
Pipeline file is used to create a small container in bitbucket infrastructure and runs the code analysis there.
This file provides information regarding
When all checks should run
What all checks should be done.
Configuration of the image and container which will be created to run the pipeline.
Cache configuration for faster builds.
Reusable build-level code components like steps etc.
bit bucket docs for reference
https://support.atlassian.com/bitbucket-cloud/docs/get-started-with-bitbucket-pipelines/
https://support.atlassian.com/bitbucket-cloud/docs/pipeline-triggers/
https://support.atlassian.com/bitbucket-cloud/docs/use-docker-images-as-build-environments/
https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/

Concourse unauthorized error pushing to Artifactory using docker-image-resource

I'm trying to use Concourse to grab a dockerfile defintion from a git repository, do some work, build the docker image, and push the new image to Artifactory. See below for the pipeline definition. At this time I have all stages up to the artifactory stage (the one that pushes to Artifactory) working. The artifactory stage exits with error with the following output:
waiting for docker to come up...
sha256:c6039bfb6ac572503c8d97f42b6a419b94139f37876ad331d03cb7c3e8811ff2
The push refers to repository [artifactory.server.com:2077/base/golang/alpine]
a4ab5bf94afd: Preparing
unauthorized: The client does not have permission to push to the repository.
This would seem straight-forward as an Artifactory permissions issue, except that I've tested locally with the docker cli and am able to push using the same user/pass as specified within destination_username and destination_password. I double checked the credentials to make sure I'm using the same ones and find that I am.
Question #1: is there any other known cause for getting this error? I've scoured the resource github page without finding anything. Any ideas why I may be getting the permissions error?
Without having an answer to the above question, I'd really like to dig deeper into troubleshooting the problem. To do so I use fly hijack to get a shell in the corresponding container. I notice that docker is installed on the container, so next step I think would be to do a docker import on the tarball for the image I'm trying to push and then perform a docker push to push it to the repo. When attempting to run the import I get the error:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is
the docker daemon running?
Question #2: Why can't I use docker commands from within the container? Perhaps this has something to do with the issue I'm seeing with pushing to repo when running the pipeline (I don't think so)? Is it because the container isn't running with privilege? I thought that the privileged argument would be supplied in the resource type definition, but if not, how can I run with privilege?
resources:
- name: image-repo
type: git
source:
branch: master
private_key: ((private_key))
uri: ssh://git#git-server/repo.git
- name: artifactory
type: docker-image
source:
repository: artifactory.server.com:2077/((repo))
tag: latest
username: ((destination_username))
password: ((destination_password))
jobs:
- name: update-image
plan:
- get: image-repo
- task: do-stuff
file: image-repo/scripts/do-stuff.yml
vars:
repository-directory: ((repo))
- task: build-image
privileged: true
file: image-repo/scripts/build-image.yml
- put: artifactory
params:
import_file: image/image.tar
Arghhhh. Found after much troubleshooting that the destination_password wasn't being picked up properly due to special characters and a lack of quotes. Fixed the issue by properly setting the password within yaml file being included with the --load-vars flag.

Resources