-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (87 loc) · 3.44 KB
/
codeql-analysis.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
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: 'Lint/Build/Push for Github Actions'
on:
push:
branches:
- main
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
branches:
- main
env:
ECR_REPOSITORY: oracle
HOME_DIR: /home/ubuntu/oracle
jobs:
build:
name: build
if: success() && github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-southeast-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Create ECR repo if missing
env:
DOCKER_REPO_NAME: ${{ env.ECR_REPOSITORY }}
run: |
aws ecr describe-repositories --repository-names ${ECR_REPOSITORY} || aws ecr create-repository --repository-name ${ECR_REPOSITORY}
- name: Set version
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Check version
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
run: |
echo $RELEASE_VERSION
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY .
docker tag $ECR_REGISTRY/$ECR_REPOSITORY $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker tag $ECR_REGISTRY/$ECR_REPOSITORY $ECR_REGISTRY/$ECR_REPOSITORY:$RELEASE_VERSION
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$RELEASE_VERSION
deploy:
name: deploy
if: success() && github.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-latest
steps:
- name: Prepare SSH environment
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }}
run: |
mkdir -p ~/.ssh/
echo "$SSH_PRIVATE_KEY" > ~/.ssh/private.key
sudo chmod 600 ~/.ssh/private.key
- name: SSH to develop environment and restart application
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
run: |
sleep 10
ssh -o StrictHostKeyChecking=no -i ~/.ssh/private.key $REMOTE_HOST "aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin 622578495407.dkr.ecr.ap-southeast-1.amazonaws.com"
ssh -o StrictHostKeyChecking=no -i ~/.ssh/private.key $REMOTE_HOST "docker pull 622578495407.dkr.ecr.ap-southeast-1.amazonaws.com/$ECR_REPOSITORY:latest && cd $HOME_DIR && docker-compose up -d"