Repository navigation
78 lines (72 loc) · 3.2 KB
/
Copy pathcicd_dev.yml
File metadata and controls
78 lines (72 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Continuous Integration notejam app
on:
push:
branches:
- feature/*
- develop
env:
RELEASE_VERSION: "dev"
EXTERNAL_DATABASE: true
jobs:
ci:
name: Build and publish Docker image
runs-on: ubuntu-latest
steps:
- name: Extract version from branch name (for release branches)
if: startsWith(github.ref, 'refs/heads/release/')
run: |
BRANCH_NAME="${{ github.ref }}"
VERSION=${BRANCH_NAME#refs/heads/release/}
echo "::set-env name=RELEASE_VERSION::$VERSION"
echo "::set-env name=EXTERNAL_DATABASE::false"
- name: Extract version from branch name (for hotfix branches)
if: startsWith(github.ref, 'refs/heads/hotfix/')
run: |
BRANCH_NAME="${{ github.ref }}"
VERSION=${BRANCH_NAME#refs/heads/hotfix/}
echo "::set-env name=RELEASE_VERSION::$VERSION"
echo "::set-env name=EXTERNAL_DATABASE::false"
- name: Extract version from branch name (for feature branches)
if: startsWith(github.ref, 'refs/heads/feature/')
run: |
BRANCH_NAME="${{ github.ref }}"
VERSION=${BRANCH_NAME#refs/heads/feature/}
echo "::set-env name=RELEASE_VERSION::$VERSION"
echo "::set-env name=EXTERNAL_DATABASE::false"
- uses: actions/checkout@v1
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8
- name: Test and package project
run: mvn -f spring/pom.xml package
- name: Build Docker image
run: docker build -t fbdo/notejam:latest -t fbdo/notejam:${{ env.RELEASE_VERSION }} spring
- name: Publish Docker image to registry
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
docker push fbdo/notejam:${{ env.RELEASE_VERSION }}
- name: "Setup GCP credentials"
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: "285.0.0"
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
service_account_key: ${{ secrets.GOOGLE_CREDENTIALS }}
export_default_credentials: true
- name: Deploy Helm chart
run: |
NAMESPACE="${RELEASE_VERSION//[.]/-}"
gcloud config set project ${{ secrets.GCP_PROJECT_ID }}
gcloud container clusters get-credentials notejam --zone=europe-west3 --project ${{ secrets.GCP_PROJECT_ID }}
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
helm upgrade -f spring/charts/notejam/values-dev.yaml notejam spring/charts/notejam --install --namespace=$NAMESPACE --set image.tag=${{ env.RELEASE_VERSION }} --set externalDatabase.enabled=${{ env.EXTERNAL_DATABASE }} --set mail.username=${{ secrets.SMTP_USERNAME }} --set mail.password=${{ secrets.SMTP_PASSWORD }}