chore: add cicd docker compose #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Compose Pipeline | |
on: | |
push: | |
branches: | |
- main | |
- staging | |
pull_request: | |
branches: | |
- main | |
- staging | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
environment: staging | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Docker Compose | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y docker-compose | |
- name: Create Environment Files | |
run: | | |
cd ./apps/frontend | |
echo "NEXT_PUBLIC_QUESTION_SERVICE_URL=${{ vars.QUESTION_SERVICE_URL }}" >> .env | |
echo "NEXT_PUBLIC_USER_SERVICE_URL=${{ vars.USER_SERVICE_URL }}" >> .env | |
cd ../question-service | |
echo "FIREBASE_CREDENTIAL_PATH=${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}" >> .env | |
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env | |
cd ../user-service | |
echo "DB_CLOUD_URI=${{ vars.USER_SERVICE_DB_CLOUD_URI }}" >> .env | |
echo "PORT=${{ vars.USER_SERVICE_PORT }}" >> .env | |
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env | |
- name: Build and Run Services | |
run: | | |
cd ./apps | |
docker-compose up --build -d | |
- name: Clean up environment files | |
run: | | |
rm ./apps/frontend/.env | |
rm ./apps/question-service/.env | |
rm ./apps/user-service/.env | |
- name: Run Tests | |
run: | | |
# check if non-error status code received | |
curl --fail ${{ vars.FRONTEND_URL }} | |
curl --fail ${{ vars.USER_SERVICE_URL }} | |
# check if any response received | |
curl -s -o /dev/null ${{ vars.QUESTION_SERVICE_URL }} | |
# We can add more tests here | |
- name: Stop Services | |
run: | | |
cd .apps | |
docker-compose down |