Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI #1

Merged
merged 12 commits into from
Apr 17, 2024
Merged

CI #1

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PORT=3000
DATABASE_URL="mysql://root:password@mysql:3306/app"
42 changes: 42 additions & 0 deletions .github/workflows/feature-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Feature Test
'on':
workflow_dispatch: null
push:
branches:
- ci/**
env:
REGISTRY: ghcr.io
IMAGE_NAME_BACKEND: '${{ github.repository }}-backend'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Clone Repo
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: '${{ env.REGISTRY }}'
username: '${{ github.actor }}'
password: '${{ secrets.GITHUB_TOKEN }}'
- name: 'Extract metadata (tags, labels) for Docker'
id: meta-backend
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME_BACKEND }}'
- name: Docker Backend
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: ./Dockerfile
push: false
tags: '${{ steps.meta-backend.outputs.tags }}'
labels: '${{ steps.meta-backend.outputs.labels }}'
- name: Containers Up
run: ./cicd/steps/run-containers.sh
env:
DOCKER_IMAGE_TS: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME_BACKEND }}'
- name: Feature Tests
run: ./cicd/steps/run-tests.sh
env:
DOCKER_IMAGE_TS: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME_BACKEND }}'
Binary file added cicd/.DS_Store
Binary file not shown.
16 changes: 16 additions & 0 deletions cicd/steps/run-containers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -eux

DC="docker-compose -f docker-compose.ci.yml"

ls -l

cp .env.example .env

${DC} up -d app mysql

sleep 20

${DC} ps

export COMPOSE_INTERACTIVE_NO_CLI=1
12 changes: 12 additions & 0 deletions cicd/steps/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -eux

DC="docker-compose -f docker-compose.ci.yml"

docker ps

${DC} exec -T app npx prisma generate

${DC} exec -T app npx prisma migrate dev

${DC} exec -T app npm run test
27 changes: 27 additions & 0 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.8'

services:
app:
image: ${DOCKER_IMAGE_TS}
build:
context: .
dockerfile: ./Dockerfile
command: ["npm", "run", "dev"]
depends_on:
- mysql

mysql:
image: mysql/mysql-server:8.0
restart: always
environment:
MYSQL_ROOT_PASSWORD: 'password'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: 'app'
MYSQL_USER: 'app_user'
MYSQL_PASSWORD: 'password'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- mysql-data:/var/lib/mysql

volumes:
mysql-data:
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ services:
mysql:
image: mysql/mysql-server:8.0
restart: always
ports:
- 3310:3306
environment:
MYSQL_ROOT_PASSWORD: 'password'
MYSQL_ROOT_HOST: "%"
Expand Down
Loading