Is it possible to push an image to AWS ECR using Google CloudBuild? - google-cloud-build

The following snippet (Node/Typescript) utilizes Google's CloudBuild API (v1) to build a container and push to Google's Container Registry (GCR). If it is possible, what's the right way to have CloudBuild push the image to AWS ECR instead of GCR?
import { cloudbuild_v1 } from "googleapis";
[...]
const manifestLocation = `gs://${manifestFile.bucket}/${manifestFile.fullpath}`;
const buildDestination = `gcr.io/${GOOGLE_PROJECT_ID}/xxx:yyy`;
const result = await builds.create({
projectId: GOOGLE_PROJECT_ID,
requestBody: {
steps: [
{
name: 'gcr.io/cloud-builders/gcs-fetcher',
args: [
'--type=Manifest',
`--location=${manifestLocation}`
]
},
{
name: 'docker',
args: ['build', '-t', buildDestination, '.'],
}
],
images: [buildDestination]
}
})```

Yes you can by setting a custom step where you do that.
for this you can have a step with the docker image that makes the build and pushes it to AWS ECR.
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', '<AWS_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/<IMAGE_NAME>', '.' ]
Here is a guide on how to use cludbuild which can be useful to you.
BAsically on your usecase you can just change the value of destination to the AWS ECR URL like this:
import { cloudbuild_v1 } from "googleapis";
[...]
const manifestLocation = `gs://${manifestFile.bucket}/${manifestFile.fullpath}`;
const buildDestination = `<AWS_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/<IMAGE_NAME>`;
const result = await builds.create({
projectId: GOOGLE_PROJECT_ID,
requestBody: {
steps: [
{
name: 'gcr.io/cloud-builders/gcs-fetcher',
args: [
'--type=Manifest',
`--location=${manifestLocation}`
]
},
{
name: 'docker',
args: ['build', '-t', buildDestination, '.'],
}
],
images: [buildDestination]
}
})```

Related

Using cypress grep tags how can we configurable tags for a automation tests

How can we make the cypress grep tags configurable for a automation tests. At the moments the tags are predefined in side the automation tests, for example: "#Smoke". This is running fine. But now I want to run few tests with a new tag like #QuickRun from gitBash CLI and it should pick up those tests having tagged with a global variable ?
I have tried as following, I have passed the "#QuickRun" from the CLI and receiving inside the test to a const variable onFlyTag, but not working at the moment. Is it possible, could someone please advise.
//GitBash CLI
CYPRESS_BASE_URL=https://staging-qa-bookingtesting.com/ npx cypress run --env grepTags="#quickRun",ENV="staging" --browser chrome
//login.spec.js
const onFlyTag = Cypress.env("grepTags");
it(
"Test-1",
{ tags: ["#Smoke", "#LoginLogout", "#Regression", `"${onFlyTag}"` ] },
//..rest of the test follows here...
);
it(
"Test-2",
{ tags: ["#Smoke", "#LoginLogout", "#Regression"] },
//..rest of the test follows here...
);
it(
"Test-3",
{ tags: ["#Smoke", "#LoginLogout", "#Regression", `"${onFlyTag}"`] },
//..rest of the test follows here...
);
It will work if you remove the double-quotes from inside the string template:
// Spec grep-tags.cy.js
const onFlyTag = Cypress.env("grepTags");
it(
"Test-1",
{ tags: ["#Smoke", "#LoginLogout", "#Regression", `${onFlyTag}`] },
() => { expect(true).to.eq(true) }
);
it(
"Test-2",
{ tags: ["#Smoke", "#LoginLogout", "#Regression"] },
() => { expect(true).to.eq(true) }
);
it(
"Test-3",
{ tags: ["#Smoke", "#LoginLogout", "#Regression", `${onFlyTag}`] },
() => { expect(true).to.eq(true) }
);
Other config
// cypress/support/e2e.js
import './commands'
import cypressGrep from '#cypress/grep';
cypressGrep();
// package.json
{
...
"scripts": {
"cy:quick": "npx cypress run --spec 'cypress/e2e/grep-tags.cy.js' --env grepTags='#quickRun'"
}
}
Output result
===================================================================================
(Run Starting)
┌─────────────────────────────────────────────────────────────────────────────────
│ Cypress: 12.3.0
│ Browser: Electron 106 (headless)
│ Node Version: v18.12.1 (C:\Program Files\nodejs\node.exe)
│ Specs: 1 found (grep-tags.cy.js)
│ Searched: ...cypress\e2e\grep-tags.cy.js
└────────────────────────────────────────────────────────────────────────────────
───────────────────────────────────────────────────────────────────────────────────
Running: grep-tags.cy.js (1 of 1)
√ Test-1 (66ms)
- Test-2
√ Test-3 (36ms)
2 passing (128ms)
1 pending

ARM Incremental deployment mode

Consider I have an Azure Function App with some app settings and some functions created via the following YAML task:
- task: AzureResourceManagerTemplateDeployment#3
displayName: 'deploy resources'
inputs:
azureResourceManagerConnection: azureResourceManagerConnection
subscriptionId:subscriptionId
resourceGroupName: rg
location:location
csmFile: template.bicep
csmParametersFile:parameters.json
deploymentMode: 'Incremental'
Let’s say I modified app settings.
If I run the above YAML task in Incremental deployment mode, does that recreate the Azure Function App with the modified app settings and functions or does it just update the app settings - Function app and existing functions stay the same?
Here is how my template.bicep looks like:
var appSettings = [
{
name: 'WEBSITE_ADD_SITENAME_BINDINGS_IN_APPHOST_CONFIG'
value: 1
}
{
name: 'WEBSITE_ENABLE_SYNC_UPDATE_SITE'
value: 1
}
{
name: 'SCM_TOUCH_WEBCONFIG_AFTER_DEPLOYMENT'
value: 0
}
{
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
value: reference(resourceId(appInsightsResourceGroup, 'microsoft.insights/components/', appInsightsName), '2015-05-01').InstrumentationKey
}
{
name: 'AzureWebJobsStorage'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};AccountKey=${listKeys(resourceId(storageAccountResourceGroup, 'Microsoft.Storage/storageAccounts', storageAccountName), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value}'
}
{
name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};AccountKey=${listKeys(resourceId(storageAccountResourceGroup, 'Microsoft.Storage/storageAccounts', storageAccountName), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value}'
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: 'dotnet'
}
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~4'
}
{
name: 'WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT'
value: maximumElasticWorkerCount
}
{
name: 'appConfigurationEndpoint'
value: appConfigurationEndpoint
}
{
name: 'membershipStorageAccountName'
value: '#Microsoft.KeyVault(SecretUri=${reference(membershipStorageAccountName, '2019-09-01').secretUriWithVersion})'
}
{
name: 'membershipContainerName'
value: '#Microsoft.KeyVault(SecretUri=${reference(membershipContainerName, '2019-09-01').secretUriWithVersion})'
}
]
var stagingSettings = [
{
name: 'WEBSITE_CONTENTSHARE'
value: toLower('functionApp-staging')
}
{
name: 'AzureFunctionsJobHost__extensions__durableTask__hubName'
value: '${solutionAbbreviation}compute${environmentAbbreviationStaging}'
}
{
name: 'AzureWebJobs.StarterFunction.Disabled'
value: 1
}
]
var productionSettings = [
{
name: 'WEBSITE_CONTENTSHARE'
value: toLower('functionApp')
}
{
name: 'AzureFunctionsJobHost__extensions__durableTask__hubName'
value: '${solutionAbbreviation}compute${environmentAbbreviation}'
}
{
name: 'AzureWebJobs.StarterFunction.Disabled'
value: 0
}
]
module functionAppTemplate 'functionApp.bicep' = {
name: 'functionAppTemplater'
params: {
name: '${functionAppName}'
kind: functionAppKind
location: location
servicePlanName: servicePlanName
dataKeyVaultName: dataKeyVaultName
dataKeyVaultResourceGroup: dataKeyVaultResourceGroup
secretSettings: union(appSettings, productionSettings)
}
dependsOn: [
servicePlanTemplate
]
}
module functionAppSlotTemplate 'functionAppSlot.bicep' = {
name: 'functionAppSlotTemplate'
params: {
name: '${functionAppName}/staging'
kind: functionAppKind
location: location
servicePlanName: servicePlanName
dataKeyVaultName: dataKeyVaultName
dataKeyVaultResourceGroup: dataKeyVaultResourceGroup
secretSettings: union(appSettings, stagingSettings)
}
dependsOn: [
functionAppTemplate
]
}
functionapp.bicep
resource functionApp 'Microsoft.Web/sites#2018-02-01' = {
name: name
location: location
kind: kind
properties: {
serverFarmId: resourceId('Microsoft.Web/serverfarms', servicePlanName)
clientAffinityEnabled: false
httpsOnly: true
siteConfig: {
use32BitWorkerProcess : false
appSettings: secretSettings
}
}
identity: {
type: 'SystemAssigned'
}
}
functionAppSlot.bicep
resource functionAppSlot 'Microsoft.Web/sites/slots#2018-11-01' = {
name: name
kind: kind
location: location
properties: {
clientAffinityEnabled: true
enabled: true
httpsOnly: true
serverFarmId: resourceId('Microsoft.Web/serverfarms', servicePlanName)
siteConfig: {
use32BitWorkerProcess : false
appSettings: secretSettings
}
}
identity: {
type: 'SystemAssigned'
}
}
Your Function App will not be recreated. Only the state or values which does not match the desired state are changed.
This means, if you change a setting e.g. FUNCTIONS_EXTENSION_VERSION in the bicep file, it will be changed in the Function App settings.
https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/overview
Repeatable results: Repeatedly deploy your infrastructure throughout the development lifecycle and have confidence your resources are deployed in a consistent manner. Templates are idempotent, which means you can deploy the same template many times and get the same resource types in the same state. You can develop one template that represents the desired state, rather than developing lots of separate templates to represent updates.

How can I query an internally deployed API from my Jelastic environment?

I am writing a Jelastic manifest where I deploy two nodes. On one node, I have an API that I need to query in order to setup the second. Something along these lines:
type: install
name: My test
nodes:
- count: 1
cloudlets: 4
nodeGroup: auth
nodeType: docker
image: my-api:latest
- count: 1
cloudlets: 16
nodeGroup: cp
nodeType: docker
image: some-service:latest
onInstall:
- script: |
import com.hivext.api.core.utils.Transport;
try {
const body = new Transport().get("http://${nodes.auth.master.intIP}:9011/api/key", {
"Authorization": "my-api-key"
});
return { result: 0, body: body };
} catch (e) {
return {
type: "error",
message: "unknown error: " + e
};
}
In my script, when I do
const body = new Transport().get("http://www.google.com");
it works, I get the body content of the google page. However,
const body = new Transport().get("http://${nodes.auth.master.intIP}:9011/api/key", {
"Authorization": "my-api-key"
});
returns
ERROR: script.response: {"type":"error","message":"unknown error: JavaException: java.io.IOException: Failed to select a proxy"}
What am I doing wrong? How can I query my service in a script like in the above snippet? When I curl it through regular cmd, then it works:
curl -s -H "Authorization: my-api-key" http://${nodes.auth.master.intIP}:9011/api/key
Also, incidentally, where can I find the documentation of com.hivext.api.core.utils.Transport?
You can't access your environment node via internal IP from the script (at least it's not guaranteed).
As a workaround, you can access your node via public IP or endpoint.
If public IP or endpoint is not applicable in your case and your service must be accessed only internally, you can try to access your node via curl and ExecCmd API. For example:
type: install
name: My test
nodes:
- count: 1
cloudlets: 4
nodeGroup: auth
nodeType: docker
image: my-api:latest
- count: 1
cloudlets: 16
nodeGroup: cp
nodeType: docker
image: some-service:latest
onInstall:
- script: |
function execInternalApi(nodeId, url) {
let resp = api.env.control.ExecCmdById({
envName: '${env.name}',
nodeId: nodeId,
commandList: toJSON([{
command: 'curl -fSsl -H "Authorization: my-api-key" \'' + url + '\''
}])
})
if (resp.result != 0) return resp
return { result: 0, out: resp.responses[0].out }
}
let body = execInternalApi(${nodes.auth.master.id}, 'http://localhost:9011/api/key');
return { result: 0, body: body };

Strapi not uploading pictures to Cloudinary

UPDATE: I installed Strapi version 3.6.3 and it works well
Strapi - Clouinary connection do not work for me. So I'm uploading pictures to Stapi, but they don't appear in Clouinary.
In config folder I created file plugins.js with following content:
module.exports = ({
env
}) => ({
// ...
upload: {
provider: 'cloudinary',
providerOptions: {
cloud_name: env('CLOUDINARY_NAME'),
api_key: env('CLOUDINARY_KEY'),
api_secret: env('CLOUDINARY_SECRET'),
},
},
// ...
});
I have installed npm i strapi-provider-upload-cloudinary
then changed file .env to
PORT=1337
CLOUDINARY_NAME="***"
CLOUDINARY_KEY="***"
CLOUDINARY_SECRET="***"```
Actually automatically following code added automatically:
```JWT_SECRET=*********
API_TOKEN_SALT=*********
JWT_SECRET=*********
What could be a problem?
should CLOUDINARY_SECRET be in "quotes"? or in 'quotes' or without quotes?
Terminal output after adding image is following:
http://localhost:1337
[2021-12-07 02:10:14.702] http: POST /upload (261 ms) 200
[2021-12-07 02:10:14.744] http: GET /upload/files?sort=updatedAt:DESC&page=1&pageSize=10 (24 ms) 200
[2021-12-07 02:10:14.758] http: GET /uploads/thumbnail_Screenshot_2021_11_26_130226_11a95e81ea.png?width=1504&height=1258 (4 ms) 200
All permissions seems to be set...
Also created extentions/upload/config/setting.json with the following content:
"provider": "cloudinary",
"providerOptions": { "cloud_name":"devert0mt",
"api_key": "***",
"api_secret":"***"
}
}{
"provider": "cloudinary",
"providerOptions": { "cloud_name":"devert0mt",
"api_key": "***",
"api_secret":"***"
}
}```
If you want to use the latest version of Strapi, v.4 and above, you need to change strapi provider package to this one:
npm install #strapi/provider-upload-cloudinary --save
Then, you need to update your plugins.js file in config/plugins.js to the following ( Be aware that it has a slightly different structure than the previous package - everything is placed in config object, instead of upload like it was on a previous version):
module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: 'cloudinary',
providerOptions: {
cloud_name: env('CLOUDINARY_NAME'),
api_key: env('CLOUDINARY_KEY'),
api_secret: env('CLOUDINARY_SECRET'),
},
actionOptions: {
upload: {},
delete: {},
},
},
},
// ...
});
Also, if you are having issues with properly rendering your images on your Strapi dashboard you can update middlewares.js in config/middlewares.js:
Instead of 'strapi::security' in module.exports, paste this:
// ...
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
'connect-src': ["'self'", 'https:'],
'img-src': ["'self'", 'data:', 'blob:', 'res.cloudinary.com'],
'media-src': ["'self'", 'data:', 'blob:', 'res.cloudinary.com'],
upgradeInsecureRequests: null,
},
},
},
},
// ...

Routing in Serverless nuxt app not working

So I'm getting a routing problem whenever I use nuxt ssr with serverless. When I use either deploy to AWS lambda or use serverless-offline it generates the url prefixed with /{stage}, but nuxt can't seem to handle this and either throws 403, 404 or 500 errors because the routes to static files aren't prefixed with /{stage}.
I have tried adding {stage} to the public path on build, the results in a 404 because now the static file path needs to prefixed with another /{stage}. If I go directly to {stage}/{stage}/_nuxt/{file} it works.
build: {
publicPath: '/{stage}/_nuxt'
}
So looking around I found that I can update the router base to the below
router: {
base: '/{stage}'
}
but now the file only loads if its {stage}/{stage}/{stage}/_nuxt/{file} and removing the publicPath code above doesn't make it work either.
And this is for the static files, when it comes to the actual routes the homepage set at '/' either works but any other pages don't because the nuxt-links to them aren't prefixed with /{stage} or if I add the prefix to the base I get a Cannot GET / error when I visit /{stage}.
I have tried many different ways of doing this such as using express however I have had no luck and any tutorials that I found online are at least 2 years old and the github repos have the same problem. The closest thing I have found on stackoverflow that is somewhat similar to what I have is here but this is for a static site.
Anybody have any ideas? Below is the code for the serverless.yaml, handler.js, nuxt.js, nuxt.config.js.
Github Repo
serverless.yaml
service: nuxt-ssr-lambda
provider:
name: aws
runtime: nodejs12.x
stage: ${env:STAGE}
region: eu-west-1
lambdaHashingVersion: 20201221
environment:
NODE_ENV: ${env:STAGE}
apiGateway:
shouldStartNameWithService: true
functions:
nuxt:
handler: handler.nuxt
events:
- http: ANY /
- http: ANY /{proxy+}
plugins:
- serverless-apigw-binary
- serverless-dotenv-plugin
- serverless-offline
custom:
apigwBinary:
types:
- '*/*'
handler.js
const sls = require('serverless-http')
const binaryMimeTypes = require('./binaryMimeTypes')
const nuxt = require('./nuxt')
module.exports.nuxt = sls(nuxt, {
binary: binaryMimeTypes
})
nuxt.js
const { Nuxt } = require('nuxt')
const config = require('./nuxt.config.js')
const nuxt = new Nuxt({ ...config, dev: false })
module.exports = (req, res) =>
nuxt.ready().then(() => nuxt.server.app(req, res))
nuxt.config.js
module.exports = {
telemetry: false,
head: {
htmlAttrs: {
lang: 'en'
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: '' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
css: [
],
plugins: [
],
components: true,
buildModules: [
'#nuxtjs/tailwindcss',
],
modules: [
],
router: {
base: '/prod'
},
build: {
}
}
Are you passing it as
<p>Path: {{ $route.path }}</p>
<NuxtLink to="/">Back to Mountains</NuxtLink>
if Yes then it should work else try going with redirect('/{stage}/_nuxt')
for an if statement put this inside else , I think it should work.

Resources