-
Notifications
You must be signed in to change notification settings - Fork 4
92 lines (88 loc) · 3.21 KB
/
cd-workflow.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
name: Docker CD
on:
push:
branches:
- dev
pull_request:
branches:
- main
types: [opened, synchronize, reopened]
jobs:
code-test:
# Kicks off the workflow and prepares Github to run coverage test using a ubuntu-latest container.
name: Code Test
runs-on: ubuntu-latest
env:
OS: ubuntu-latest
PYTHON: '3.9'
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.9
# Install dependencies required for tests
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install libxml2-dev libxmlsec1-dev -y --no-install-recommends
python -m pip install --upgrade pip
pip install -r ./requirements.txt
# Start running test scripts and generate the coverage report
- name: Generate Coverage Report
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
CERT_VOLUME: ${{ secrets.CERT_VOLUME }}
run: |
echo "Cloning private repository"
git clone https://openlxp-host:${{ secrets.ACCESS_TOKEN }}@github.com/OpenLXP/openlxp-private.git
echo "Private repository cloned successfully"
echo "Copying .env file from openlxp-private to current working directory"
cp ./openlxp-private/openlxp-xss-env/.env .
echo "Copied .env file successfully"
echo "Create openlxp docker network"
docker network create openlxp
echo "Docker network successfully created"
echo "Running coverage unit test"
docker-compose --env-file ./.env run app sh -c "python manage.py waitdb && coverage run manage.py test --tag=unit && flake8 && coverage report && coverage report --fail-under=80"
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
build:
# require dependency from step above
needs: code-test
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout Code
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: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPO }}
IMAGE_TAG: xss
run: |
echo "Starting docker build"
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
echo "Pushing image to ECR..."
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG