-
Notifications
You must be signed in to change notification settings - Fork 3
101 lines (82 loc) · 2.98 KB
/
gcp.yml
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: workflow
on:
push:
branches:
- main
paths-ignore:
- 'README.md'
permissions:
id-token: write
contents: read
jobs:
integration:
name: Continous Integration
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Lint code
run: echo "Linting repository"
- name: run test
run: echo "Test complete"
build-push-gcr:
name: Build and Push to GCP
needs: integration
runs-on: ubuntu-latest
env:
REPOSITORY: language-identification-docker-repo
IMAGE_NAME: language-identification-docker-image
IMAGE_TAG: latest
PROJECT_ID: project-neuron-368805
GAR_LOCATION: asia-south1
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Authenticate with Google
uses: 'google-github-actions/auth@v0'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: Login to Artifact Registry
uses: docker/login-action@v1
with:
registry: asia.gcr.io
username: _json_key
password: ${{ secrets.GCP_CREDENTIALS }}
- name: Login to Artifact Registry
run: gcloud auth configure-docker $GAR_LOCATION-docker.pkg.dev
- name: Docker build
run: docker build -t "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE_NAME:$IMAGE_TAG" .
- name: Docker Push
run: docker push "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE_NAME:$IMAGE_TAG"
pull-and-deploy:
name: Continuous Deployment
needs: build-push-gcr
runs-on: self-hosted
env:
REPOSITORY: language-identification-docker-repo
IMAGE_NAME: language-identification-docker-image
IMAGE_TAG: latest
PROJECT_ID: project-neuron-368805
GAR_LOCATION: asia-south1
steps:
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v0
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: Login to Artifact Registry
uses: docker/login-action@v1
with:
registry: asia.gcr.io
username: _json_key
password: ${{ secrets.GCP_CREDENTIALS }}
- name: Login to Artifact Registry
run: gcloud auth configure-docker $GAR_LOCATION-docker.pkg.dev
- name: Authenticate to Artifact Registry
run: gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin "$GAR_LOCATION-docker.pkg.dev"
- name: Docker pull
run: docker pull "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE_NAME:$IMAGE_TAG"
- name: Run Image
run: |-
docker run -d -e AWS_ACCESS_KEY_ID="${{ secrets.AWS_ACCESS_KEY_ID }}" -e AWS_SECRET_ACCESS_KEY="${{ secrets.AWS_SECRET_ACCESS_KEY }}" -p 80:8080 "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE_NAME:$IMAGE_TAG"
- name: Docker System Prune to Remove Old Images
run: sudo docker system prune -f