Skip to content

Commit c679877

Browse files
committed
Adds supporting CI files
- `.ci.env` will be used in the CI process. It gets renamed to `.env` and contains a basic environemnt so that docker-compose can start the services. - `build-and-deploy.yaml` will be run by GH Actions. It will build the container images you specify by installing a docker-compose Action and using`docker-compose build --push`.
1 parent 7331838 commit c679877

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

.ci.env

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This file is used to allow CI to start the compose services. It will typcially
2+
# not need to be modified.
3+
4+
MYSQL_DATABASE=mysql_database
5+
MYSQL_USER=mysql_user
6+
MYSQL_PASSWORD=mysql_password
7+
MYSQL_PORT=3306
8+
MYSQL_ROOT_PASSWORD=test123!
9+
MYSQL_HOST=db
10+
11+
ALLOWED_HOSTS='127.0.0.1,localhost'
12+
CORS_ORIGIN_WHITELIST='http://127.0.0.1:3000,http://localhost:3000'
13+
CSRF_TRUSTED_ORIGINS='http://127.0.0.1:8000,http://localhost:8000'
14+
15+
SECRET_KEY='secret_key'
16+
DEBUG='True'
17+
18+
# Add the following to your local .env file. They will be used in the CI process
19+
# and you can largely forget about them, but including them in your .env file
20+
# will act like a safe default and help suppress warnings.
21+
REGISTRY=""
22+
TAG=""
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: 'Build and deploy application containers'
2+
on:
3+
push:
4+
jobs:
5+
build-tag-push-deploy:
6+
runs-on: ubuntu-latest
7+
# CI will run for these branches
8+
if: >
9+
github.ref == 'refs/heads/main' ||
10+
github.ref == 'refs/heads/develop' ||
11+
github.ref == 'refs/heads/set-up-deployment'
12+
strategy:
13+
matrix:
14+
# Specify the docker-compose services to build images from
15+
service: [sdwebapp, sdnginx]
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
- name: Login to GitHub container registry
20+
uses: docker/login-action@v1
21+
with:
22+
registry: ghcr.io
23+
username: cmu-delphi-deploy-machine
24+
password: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }}
25+
- name: Create container image tags
26+
id: image-tag
27+
run: |
28+
baseRef="${GITHUB_REF#*/}"
29+
baseRef="${baseRef#*/}"
30+
case "${baseRef}" in
31+
main)
32+
image_tag="latest"
33+
;;
34+
*)
35+
image_tag="${baseRef//\//_}" # replace `/` with `_` in branch name
36+
;;
37+
esac
38+
echo "IMAGE_TAG=${image_tag}" >> $GITHUB_OUTPUT
39+
- name: Copy env file
40+
run: |
41+
cp ./.ci.env ./.env
42+
- name: Set up docker-compose
43+
uses: ndeloof/[email protected]
44+
- name: docker-compose build --push
45+
run: |
46+
docker-compose build --push ${{ matrix.service }}
47+
env:
48+
TAG: ":${{ steps.image-tag.outputs.IMAGE_TAG }}"
49+
REGISTRY: "ghcr.io/${{ github.repository_owner }}/"
50+
- name: docker-compose down
51+
run: |
52+
docker-compose down
53+
- name: Trigger smee.io webhook to pull new container images
54+
run: |
55+
curl -H "Authorization: Bearer ${{ secrets.DELPHI_DEPLOY_WEBHOOK_TOKEN }}" \
56+
-X POST ${{ secrets.DELPHI_DEPLOY_WEBHOOK_URL }} \
57+
-H "Content-Type: application/x-www-form-urlencoded" \
58+
-d "repository=ghcr.io/${{ github.repository }}-${{ matrix.service }}&tag=${{ steps.image-tag.outputs.IMAGE_TAG }}"

0 commit comments

Comments
 (0)