Deploy different branches to different Heroku applications with Travis-CI - github

In my github repo I have two branches: master and release. So currently having this .travis.yml configuration:
deploy:
provider: heroku
api_key:
secure: [MY-ENCRYPTED-KEY]
app: myapp
on:
repo: helloworld/myapp
branch: release
run:
- restart
skip_cleanup: true
makes it possible to deploy a heroku app named myapp from the release branch.
According to the documentation, I can specify a custom application name like so (dev and production keys):
deploy:
provider: heroku
api_key:
secure: [MY-ENCRYPTED-KEY]
app:
dev: myapp-dev
production: myapp
on:
repo: helloworld/myapp
branch: release
run:
- restart
skip_cleanup: true
Now the question is:
How can I specify the branch for each app? Like:
master branch -> myapp-dev (dev)
release branch -> myapp (production)
The documentation is not clear on this...

It's not stated anywhere in the documentation, but it turned out the key names in the app section actually correspond to branch names:
deploy:
provider: heroku
api_key:
secure: [MY-ENCRYPTED-KEY]
app:
master: myapp-dev
release: myapp
on:
repo: helloworld/myapp
run:
- restart
skip_cleanup: true

Related

Github Actions - Invalid workflow file

I am trying to build CI/CD pipelines using GitHub Actions but unfortunately, I am stuck with an error with the yaml file.
Here is my Yaml file is:
---
name: Build and push python code to gcp with github actions
on:
push:
branches:
- main
jobs:
build_push_grc:
name: Build and push to gcr
runs_on: unbuntu-latest
env:
IMAGE_NAME: learning_cicd
PROJECT_ID: personal-370316
steps:
- name: Checkoutstep
uses: actions/checkout#v2
- uses: google-github-actions/setup-gcloud#master
with:
service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY}}
project_id: ${{ env.PROJECT_ID }}
export_default_credentials: true
- name: Build Docker Image
run: docker build -t $IMAGE_NAME:latest .
- name: Configure Docker Client
run: |-
gcloud auth configure-docker --quiet
- name: Push Docker Image to Container Registry (GCR)
env:
GIT_TAG: v0.1.0
run: |-
docker tag $IMAGE_NAME:latest gcr.io/$PROJECT_ID/$IMAGE_NAME:latest
docker tag $IMAGE_NAME:latest gcr.io/$PROJECT_ID/$IMAGE_NAME:$GIT_TAG
docker push gcr.io/$PROJECT_ID/$IMAGE_NAME:latest
docker push gcr.io/$PROJECT_ID/$IMAGE_NAME:$GIT_TAG
Here is an error where I am stuck with:
GitHub Actions
/ .github/workflows/gcp.yaml
Invalid workflow file
You have an error in your yaml syntax on line 15
I tried all possible indentations available on the internet but had no luck. I tried Yamllinter but still could not find where the error comes from. Please point me to where I am going wrong.
Thanks.
The runs-on (not runs_on) should have two spaces indentation relative to the job identifier. Also, the OS should be ubuntu-latest.
Then, env should have the same indentation as runs-on or name, the same as steps.
Here is the correct WF:
---
name: Build and push python code to gcp with github actions
on:
push:
branches:
- main
jobs:
build_push_grc:
name: Build and push to gcr
runs-on: ubuntu-latest
env:
IMAGE_NAME: learning_cicd
PROJECT_ID: personal-370316
steps:
- name: Checkoutstep
uses: actions/checkout#v2
- uses: google-github-actions/setup-gcloud#master
with:
service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY}}
project_id: ${{ env.PROJECT_ID }}
export_default_credentials: true
- name: Build Docker Image
run: docker build -t $IMAGE_NAME:latest .
- name: Configure Docker Client
run: |-
gcloud auth configure-docker --quiet
- name: Push Docker Image to Container Registry (GCR)
env:
GIT_TAG: v0.1.0
run: |-
docker tag $IMAGE_NAME:latest gcr.io/$PROJECT_ID/$IMAGE_NAME:latest
docker tag $IMAGE_NAME:latest gcr.io/$PROJECT_ID/$IMAGE_NAME:$GIT_TAG
docker push gcr.io/$PROJECT_ID/$IMAGE_NAME:latest
docker push gcr.io/$PROJECT_ID/$IMAGE_NAME:$GIT_TAG
I would recommend debugging such issues in the GitHub file edit form (editing the yml file in the .github/workflows directory). It will highlight all the issues regarding the workflow syntax. Demo.

Gitlab automatically stops environment after merge

In our team we have multiple static environments. There is always dev and test and for certain customers where our infrastructure is allowed to deploy also staging and prod. We want to migrate our CI/CD Pipelines from Teamcity to Gitlab but something that was causing many troubles is how Gitlab behaves when we merge a MR which is able to be deployed onto a static environment. We're not able to just deploy each MR on its own environment which was no problem with TeamCity as we could just deploy every branch onto every environment.
For the deployment itself we use Terraform although I have a testing repository which just echos a small text as a test.
Something which is especially confusing is that Gitlab stops an environment even though it was never deployed from the MR.
Something gets merged into develop
This commit is deployed onto e.g. test
A new branch is merged into develop
Gitlab stops the test environment even though it got never deployed to from the MR
Is this something that is just not possible with Gitlab as of now or have we missed a configuration option? Protected environments are not available for us but I also feel like this wouldn't be the right option for the problem we're facing.
The following is the pipeline of my test repository.
stages:
- deploy
- destroy-deployment
### Deployment
deployment-prod:
extends: .deployment
environment:
on_stop: destroy-deployment-prod
url: http://proto.url
deployment_tier: production
variables:
ENVIRONMENT: prod
rules:
- if: $CI_COMMIT_TAG
destroy-deployment-prod:
extends: .destroy-deployment
variables:
ENVIRONMENT: prod
environment:
url: http://proto.url
deployment_tier: production
action: stop
rules:
- if: $CI_COMMIT_TAG
when: manual
### Deployment-Test
deployment-test:
extends: .deployment
environment:
on_stop: destroy-deployment-test
url: http://test.proto.url
deployment_tier: testing
variables:
ENVIRONMENT: test
when: manual
destroy-deployment-test:
extends: .destroy-deployment
variables:
ENVIRONMENT: test
environment:
url: http://test.proto.url
deployment_tier: testing
action: stop
### Deployment-Staging
deployment-staging:
extends: .deployment
environment:
on_stop: destroy-deployment-staging
url: http://staging.proto.url
deployment_tier: staging
variables:
ENVIRONMENT: staging
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
destroy-deployment-staging:
extends: .destroy-deployment
variables:
ENVIRONMENT: staging
TF_VAR_host: staging.proto.url
environment:
url: http://staging.proto.url
deployment_tier: staging
action: stop
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: manual
### Deployment-Dev
deployment-dev:
extends: .deployment
environment:
on_stop: destroy-deployment-dev
url: http://dev.proto.url
deployment_tier: development
variables:
ENVIRONMENT: dev
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
destroy-deployment-dev:
extends: .destroy-deployment
variables:
ENVIRONMENT: dev
TF_VAR_host: dev.proto.url
environment:
url: http://dev.proto.url
deployment_tier: development
action: stop
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
when: manual
### Deployment Templates
.deployment:
image: alpine
stage: deploy
script:
- echo "Deploying $ENVIRONMENT"
resource_group: proto-$ENVIRONMENT
environment:
name: $ENVIRONMENT
url: http://$ENVIRONMENT.proto.url
rules:
- when: manual
.destroy-deployment:
image: alpine
stage: destroy-deployment
script:
- echo "Destroy $ENVIRONMENT"
resource_group: proto-$ENVIRONMENT
environment:
name: $ENVIRONMENT
url: http://$ENVIRONMENT.proto.url
action: stop
when: manual
rules:
- when: manual
I have similar problem, don't understand the reasons of such behaviour. But I figured out that it depends on your default env variable.
I wonder if you're running into this bug?: Merging triggers manual environment on_stop action
It seems like a regression that was introduced in GitLab 14.9 and fixed in GitLab 14.10.
In GitLab 14.10, to get the fix you need to enable this feature flag: fix_related_environments_for_merge_requests
In GitLab 15.0, the fix is enabled by default.

Yii2 deploy using GitHub actions

I was using the following configuration to deploy Yii2 applications with GitHub actions:
name: Build and Deploy - DEV
on:
push:
branches:
- development
jobs:
build:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout#master
- name: Setup Enviroment
uses: shivammathur/setup-php#v2
with:
php-version: '7.2'
- name: Install Packages
run: composer install --no-dev --optimize-autoloader
- name: Deploy to Server
uses: yiier/yii2-base-deploy#master
with:
user: github
host: ${{ host }}
path: ${{ path }}
owner: github
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
- name: Apply migration
run: php yii migrate --interactive=0
It worked quite well, but now is giving this error:
Current runner version: '2.285.1'
Operating System
Virtual Environment
Virtual Environment Provisioner
GITHUB_TOKEN Permissions
Secret source: Actions
Prepare workflow directory
Prepare all required actions
Getting action download info
Error: Unable to resolve action `yiier/yii2-base-deploy#master`, repository not found
Appears that yiier/yii2-base-deploy#master no longer existis.
Anyone knows a replacer?
Thanks!
Thanks to SiZE comment i remember I had fork the original repo.

Show deployed application versions in Environments tab

I have a deployment pipeline in azure-devops and it takes artifacts from other pipelines and deploy it to different environments. Yml looks like this:
...
resources:
repositories:
- repository: self
trigger:
branches:
include:
- develop
- release
- master
pipelines:
- pipeline: pipeline-1
source: different-repo-pipeline-1
- pipeline: pipeline-2
source: different-repo-pipeline-2
...
jobs:
- deployment: some-name
environment: develop
strategy:
runOnce:
deploy:
steps:
- download: pipeline-1
- download: pipeline-2
# Do real deployment
After deployment on target environment tab I saw:
There is no clue on it about deployed versions. I know this version inside deployment steps, or at least can use variables from pipelines (resources.pipeline.pipeline-1.runName). But I don't see any options to add this info to Environment deployment tab. Can it be done in some ways?
No, this is not possible. We don't have any way to control what is displayed on environment tab.

gh-pages deployment issue, job fails on deploy. The directory you're trying to deploy ... doesn't exist

gh-pages deployment fails with next error: My repository failed job
Checking configuration and starting deployment… 🚦
Error: The directory you're trying to deploy named /home/runner/work/azure-flask-react/azure-flask-react/dist doesn't exist. Please double check the path and any prerequisite build scripts and try again. ❗
Deployment failed! ❌
I'm trying to deploy ReactApp at Github and besides deploy Python-Flask backend hosted at Azure and back-app has its automatically generated job yml.
But for front-app I followed this answer and manually added second job in yml because I need to provide env.variables.
My backend deployment succeeds but front-app constantly fails because of duplicated path
/home/runner/work/azure-flask-react/azure-flask-react/dist
Here is my yml and package.json but there is no any extra mentioning of that directory...
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Python app to Azure Web App - first-py-app
on:
push:
branches:
- main
workflow_dispatch:
jobs:
front-build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v1
- name: Build
run: |
npm --prefix front-app install
npm --prefix front-app run-script build
env:
REACT_DEV_SERVER_URL: ${{ secrets.REACT_DEV_SERVER_URL }},
REACT_DEV_FRONT_APP_URL: ${{ secrets.REACT_DEV_FRONT_APP_URL }}
- name: Deploy
uses: JamesIves/github-pages-deploy-action#releases/v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN_KEY }}
BRANCH: gh-pages
FOLDER: dist
back-build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#master
- name: Set up Python version
uses: actions/setup-python#v1
with:
python-version: '3.8'
- name: Build using AppService-Build
uses: azure/appservice-build#v2
with:
platform: python
platform-version: '3.8'
- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy#v2
with:
app-name: 'first-py-app'
slot-name: 'production'
publish-profile: ${{ secrets.AzureAppService_PublishProfile_7edcdecca83a4354a87943f94bb32fca }}
{
...
"homepage": "https://nikonov91-dev.github.io/azure-flask-react",
"scripts": {
...
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
}
and my file structure
azure-proj
|-front-app (containing reactjs)
|-package.json
|-node_modules
|-src
|-app.py (python-flask application which deploys successfully)
I misunderstood the issue message, the problem was not duplicating the problem was the missed inner path passed in FOLDER in gh-pages YML settings
There was a hint in BUILD step
And one more thing: do not forget to get and add to GH your personal-access-token