Update deployment.yml #38
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: CI - Run tests dockerize and push to Docker Hub | |
on: | |
push: | |
branches: ["master"] | |
pull_request: | |
branches: ["master"] | |
jobs: | |
run-tests: | |
name: Run unit tests and e2e | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [16] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: "npm" | |
- run: npm ci | |
- run: npm run test:client | |
- run: npm run test:server | |
- run: npm run test:client:cy | |
dockerize-build-and-push: | |
needs: run-tests | |
name: Dockerize application | |
runs-on: ubuntu-latest | |
env: | |
docker-images: "tv-app_react-webapp,tv-app_nodejs" | |
strategy: | |
matrix: | |
node-version: [16] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: "npm" | |
- name: Create .env file | |
run: | | |
touch .env | |
echo "${{ secrets.TV_APP_PROD_ENV }}" > .env | |
cat .env | |
- name: Dockerize services | |
run: docker-compose -f "docker-compose.prod.yml" up -d --build | |
- name: Stop services | |
if: always() | |
run: docker-compose -f "docker-compose.prod.yml" down | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Push to Docker Hub | |
run: | | |
IFS=',' read -r -a images <<< "${{ env.docker-images }}" | |
for image in ${images[@]} | |
do | |
docker tag $image ${{ secrets.DOCKERHUB_USERNAME }}/$image:${{ github.sha }} | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/$image:${{ github.sha }} | |
done |