-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (116 loc) · 4.35 KB
/
ci_cd.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: CI/CD
on:
pull_request:
branches:
- development
push:
branches:
- development
- base
jobs:
build:
if: github.ref != 'refs/heads/base' || github.ref != 'refs/heads/development'
runs-on: ubuntu-latest
env:
APPLICATION_NAME: gemini
CONTAINER: gemini-web
APPLICATION_PORT: 8006
services:
docker:
image: docker:stable
options: --privileged
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Cache dependencies
uses: actions/cache@v2
with:
path: |
$HOME/.cache/pip
$HOME/.cache/pre-commit
key: ${{ runner.os }}-pip-${{ hashFiles('**/*.lock') }}
- name: Copy config file
run: cp ${{ env.APPLICATION_NAME }}/config.py.example ${{ env.APPLICATION_NAME }}/config.py
- name: Login to Docker
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Start Docker containers
run: docker-compose up -d
- name: Wait for services to be ready
run: ./wait-for-it.sh $CONTAINER:$APPLICATION_PORT -- docker-compose exec -T $CONTAINER pip install coverage
- name: Install pre-commit
run: |
pip install "pre-commit===2.13.0"
pre-commit install
- name: Run pre-commit checks
run: pre-commit run --all-files --show-diff-on-failure
- name: Run tests with coverage
run: docker-compose exec -T $CONTAINER coverage run manage.py test
- name: Generate coverage report
run: docker-compose exec -T $CONTAINER coverage report --omit=*/migrations/* -m
deploy:
needs: build
runs-on: ubuntu-latest
#if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/development'
#CHANGE THIS TO BRANCH NAME AFTER TESTING
environment:
name: development
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Export secrets to environment variables
uses: oNaiPs/[email protected]
with:
secrets: ${{ toJSON(secrets) }}
- name: Clone deploy scripts if not present
run: |
if [ ! -d deploy_scripts ]; then
git clone https://github.com/RockefellerArchiveCenter/deploy_scripts.git;
fi
- name: Substitute environment variables
uses: tvarohohlavy/[email protected]
with:
files: |
$APPLICATION_NAME/config.py.deploy
.env.deploy
appspec.yml.deploy
deploy_scripts/create_apache_config.sh.deploy
deploy_scripts/curl_index.sh.deploy
deploy_scripts/curl_status_endpoint.sh.deploy
deploy_scripts/install_dependencies_django.sh.deploy
deploy_scripts/restart_apachectl.sh.deploy
deploy_scripts/run_management_commands_django.sh.deploy
deploy_scripts/set_permissions.sh.deploy
deploy_scripts/stop_cron.sh.deploy
- name: Rename deploy files
run: |
for TEMPLATE in ${APPLICATION_NAME}/config.py.deploy \
.env.deploy \
appspec.yml.deploy \
deploy_scripts/*.deploy
do
if [[ -f "$TEMPLATE" ]]; then
sed -e 's/\(\.deploy\)*$//g'`
rm $TEMPLATE
fi
done
- name: Create deployment zip
run: sudo deploy_scripts/make_zip_django.sh $DEPLOY_ZIP_DIR $DEPLOY_ZIP_NAME
- name: Configure AWS Credentials
uses: aws-actions/[email protected]
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: us-east-1
- name: Deploy to S3
run: aws s3 sync $DEPLOY_ZIP_DIR s3://$AWS_BUCKET_NAME
#- name: Deploy to AWS CodeDeploy
# run: aws deploy create-deployment
# --region us-east-1
# --application-name ${{ env.APPLICATION_NAME }}
# --deployment-config-name CodeDeployDefault.OneAtATime
# --deployment-group-name ${{ secrets.DEPLOYMENT_GROUP }}
# --s3-location bucket=${{ secrets.AWS_BUCKET_NAME }},bundleType=zip,key=${{ secrets.DEPLOY_ZIP_NAME }}