How to deploy a Serverless function using Gitlab CI? - environment-variables

I'm trying to deploy my Serverless function using a .gitlab-ci.yml file, and to inject environment variables into my function I'm using this format in my serverless.yml file:
${file(./serverless.env.yml):${opt:stage, 'dev'}.VARIABLE_1_KEY}
My serverless.env.yml file looks something like this:
staging:
VARIABLE_1_KEY: xxxxxxx
VARIABLE_2_KEY: xxxxxxx
SUBNET_IDS:
- xxxxxx
- xxxxxx
production:
VARIABLE_1_KEY: xxxxxxx
VARAIBLE_2_KEY: xxxxxxx
SUBNET_IDS:
- xxxxxx
- xxxxxx
My issue is that I'm not committing my serverless.env.yml file, which means Gitlab won't be able to use it to deploy the function.
I could alter the variables to this format ${env:VARIABLE_KEY} but this leaves me with the issue where the SUBNET_IDS are a list of values and doesn't work when resolving the value from an environment variable.
Is there a better way to define secrets within the project that is compatible with the Gitlab CI process?

To define project level secrets you can go to:
Your Project -> Settings -> CI/CD -> Variables
The secrets will be available via environment variables. You can read more about variables here
Regarding your issue with SUBNET_IDS list. You can either define each one as a different variable, or you can concat them with a character (, or ; for example) and split them in your script.

Related

How to get value from .gitlab-ci.yml file in vue app?

I would like to have the following implementation for getting a variable from .gitlab-ci.yml file. And depending on the variable set in the CI on gitlab, apply styles for your application on vue 3. But I don't know how to create a chain to pass this name to the frontend.
gitlab-ci.yml
variables:
BRAND_NAME: "FIRST_NAME"
app.vue
console.log(BRAND_NAME)
Unfortunately, I don't even have any idea how to implement it. For assembly and deployment I use docker and vite.

How to access Bitrise Secret Environment Variable in Swift code?

I'm using Bitrise as a CI solution for my iOS app. I would like not to commit my API token to the repository, hence I've stored it as a Secret in the workflow in Bitrise with key = "API_TOKEN"
I need to pass that value to my app as an environment variable and use it as follows:
ProcessInfo.processInfo.environment["API_TOKEN"]
However, this is always nil.
My bitrise.yml contains the following:
....
app:
envs:
- API_TOKEN: "${API_TOKEN}"
...
How can I correctly set the Secret from Bitrise as an environment variable for my iOS app?

NextJS: Prevent env vars to be required on build time

We are working on a Dockerized NextJS application that is thought to be built once and deployed to several environments for which we will have different configuration. This configuration is to be set in the Docker container when deployed as environment variables.
In order to achieve this, we are using next.config.js file, splitting the vars on serverRuntimeConfig and publicRuntimeConfig as suggested here, and we are getting the values for the environment variables from process.env. i.e.:
module.exports = {
serverRuntimeConfig: {
mySecret: process.env.MY_SECRET,
secondSecret: process.env.SECOND_SECRET,
},
publicRuntimeConfig: {
staticFolder: process.env.STATIC_FOLDER_URL,
},
}
The problem we have is that these variables are not set on build time (when we run next build), as they are environment specific and supposed to be set on deployment. Because of this, the build fails complaining about the missing variables.
Making a build per environment is not an option: as referred before, we want to build it once (with next build), put the output of the build in a docker container, and use that docker container deploy in several environments.
Is there any way to solve this so that the application builds without environment vars and we pass them afterwards on runtime (deployment)?
We finally found the issue.
We were importing code in a helper that was being used in the isomorphic side and was relaying on serverRuntimeConfig variables, being then required on build time in order to create the bundle.
Removing the import from the helper fixed the issue.

Deploy Ruby on Rails app to App Engine using Cloud Build

I'm trying to automate the deployment of a Ruby on Rails app to App Engine using Cloud Build.
My app.yaml looked like this,
runtime: ruby
env: flex
entrypoint: bundle exec rails server
But I'm getting this error,
Step #1: ERROR: (gcloud.app.deploy) There is a cloudbuild.yaml in the current directory, and the runtime field in /workspace/app.yaml is currently set to [runtime: ruby]. To use your cloudbuild.yaml to build a custom runtime, set the runtime field to [runtime: custom]. To continue using the [ruby] runtime, please remove the cloudbuild.yaml from this directory.
Then I tried to change the runtime to custom and add a Dockerfile as custom runtime needs a Dockerfile.
But now I'm getting an error saying,
ERROR: (gcloud.app.deploy) A custom runtime must have exactly one of [Dockerfile] and [cloudbuild.yaml] in the source directory; [/home/milindu/Projects/ElePath-Ruby] contains both
Then I removed Dockerfile also. But now getting into this weird situation. You can see the 'Step #1:' is growing into several like stuck in a recursion.
Cloudbuild.yaml should work with App Engine Flexible without the need to use a custom runtime. As detailed in the first error message you received, you cannot have an app.yaml and the cloudbuild.yaml in the same directory if you are deploying in a non-custom runtime, to remedy the situation, follow these steps:
Move your app.yaml and other ruby files into a subdirectory (use your
original app.yaml, no need to use custom runtime)
Under your cloudbuild.yaml steps, modify the argument for app deploy
by adding a third one specifying your app.yaml's path.
Below is an example:
==================FROM:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy']
timeout: '1600s'
===================TO:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy', '[SUBDIRECTORY/app.yaml]']
timeout: '1600s'

Vue.Js Docker Variables

I have a static site Vue.Js docker image built on nginx:alpine.
In a component, there is a URL variable for an EndPoint - I would like to be able to change this variable. I understand that I only have access to ENV variables at the build stage after this everything is static.
What I want to achieve is being able to build 1 image: that I can deploy Test-Staging-Prod environments setting a different URL for each.
I can run a script that uses variable substitution on deploy that would replace the URL e.g #{url:urlEndpoint} in the js file (i can see it in plaintext) - but this is dangerous for the obvious reasons.
How can set this up and pass the url in Vue.Js without having different images for Test Staging etc?

Resources