From f90f1226e3a9b0639528609a50349773a5e7ac7c Mon Sep 17 00:00:00 2001 From: Utwo Date: Mon, 8 Nov 2021 19:45:17 +0200 Subject: [PATCH] Update CI (#167) --- .github/workflows/build-prod.yml | 45 ------------------------ .github/workflows/build-stage.yml | 45 ------------------------ .github/workflows/deploy-prod.yml | 50 ++++++++++++++++++++++++++ .github/workflows/deploy-stage.yml | 56 ++++++++++++++++++++++++++++++ README.md | 31 ++++++++++------- 5 files changed, 125 insertions(+), 102 deletions(-) delete mode 100644 .github/workflows/build-prod.yml delete mode 100644 .github/workflows/build-stage.yml create mode 100644 .github/workflows/deploy-prod.yml create mode 100644 .github/workflows/deploy-stage.yml diff --git a/.github/workflows/build-prod.yml b/.github/workflows/build-prod.yml deleted file mode 100644 index af12a11..0000000 --- a/.github/workflows/build-prod.yml +++ /dev/null @@ -1,45 +0,0 @@ -on: - push: - branches: - - master - -name: Build & Deploy API Production - -env: - IMAGE_NAME: ${{ secrets.DOCKER_HUB_ORGANIZATION || 'code4romania' }}/rezultate-vot-api - -jobs: - build-parser: - name: Build API container - runs-on: ubuntu-latest - - steps: - - name: Checkoout - uses: actions/checkout@v2 - - - name: Build Docker image - run: | - cd src - docker build . \ - --tag $IMAGE_NAME:$GITHUB_SHA \ - --file ElectionResults.API/Dockerfile - - name: Upload Docker image - run: | - echo ${{ secrets.DOCKER_HUB_PASSWORD }} | \ - docker login \ - -u ${{ secrets.DOCKER_HUB_USERNAME }} \ - --password-stdin - docker push $IMAGE_NAME:$GITHUB_SHA - - name: Tag Latest - run: | - docker tag \ - $IMAGE_NAME:$GITHUB_SHA \ - $IMAGE_NAME:latest - docker push $IMAGE_NAME:latest - - name: Update and restart API - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.PROD_SERVER_IP }} - username: ${{ secrets.PROD_SERVER_SSH_USERNAME }} - key: ${{ secrets.PROD_SERVER_SSH_KEY }} - script: "/home/ubuntu/restart.sh" \ No newline at end of file diff --git a/.github/workflows/build-stage.yml b/.github/workflows/build-stage.yml deleted file mode 100644 index 040dd66..0000000 --- a/.github/workflows/build-stage.yml +++ /dev/null @@ -1,45 +0,0 @@ -on: - push: - branches: - - develop - -name: Build & Deploy API Staging - -env: - IMAGE_NAME: ${{ secrets.DOCKER_HUB_ORGANIZATION || 'code4romania' }}/rezultate-vot-api-stage - -jobs: - build-parser: - name: Build API container - runs-on: ubuntu-latest - - steps: - - name: Checkoout - uses: actions/checkout@v2 - - - name: Build Docker image - run: | - cd src - docker build . \ - --tag $IMAGE_NAME:$GITHUB_SHA \ - --file ElectionResults.API/Dockerfile - - name: Upload Docker image - run: | - echo ${{ secrets.DOCKER_HUB_PASSWORD }} | \ - docker login \ - -u ${{ secrets.DOCKER_HUB_USERNAME }} \ - --password-stdin - docker push $IMAGE_NAME:$GITHUB_SHA - - name: Tag Latest - run: | - docker tag \ - $IMAGE_NAME:$GITHUB_SHA \ - $IMAGE_NAME:latest - docker push $IMAGE_NAME:latest - - name: Update and restart API - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.STAGING_SERVER_IP }} - username: ${{ secrets.STAGING_SERVER_SSH_USERNAME }} - key: ${{ secrets.STAGING_SERVER_SSH_KEY }} - script: "/home/ubuntu/restart.sh" \ No newline at end of file diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml new file mode 100644 index 0000000..dcb2bfd --- /dev/null +++ b/.github/workflows/deploy-prod.yml @@ -0,0 +1,50 @@ +on: + push: + tags: + - "v*" + +name: Deploy + +env: + DOCKER_IMAGE_BASE: code4romania/rezultate-vot-api + +jobs: + build-dockerimage: + name: Build Docker container + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Set tag env + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./src + file: src/ElectionResults.API/Dockerfile + builder: ${{ steps.buildx.outputs.name }} + push: true + tags: ${{ env.DOCKER_IMAGE_BASE }}:latest,${{ env.DOCKER_IMAGE_BASE }}:${{ env.RELEASE_VERSION }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache diff --git a/.github/workflows/deploy-stage.yml b/.github/workflows/deploy-stage.yml new file mode 100644 index 0000000..e3fb140 --- /dev/null +++ b/.github/workflows/deploy-stage.yml @@ -0,0 +1,56 @@ +on: + push: + branches: + - develop + +name: Build & Deploy API Staging + +env: + IMAGE_NAME: code4romania/rezultate-vot-api + +jobs: + build-parser: + name: Build API container + runs-on: ubuntu-latest + + steps: + - name: Checkoout + uses: actions/checkout@v2 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./src + file: src/ElectionResults.API/Dockerfile + builder: ${{ steps.buildx.outputs.name }} + push: true + tags: ${{ env.DOCKER_IMAGE_BASE }}:${{ env.GITHUB_SHA }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Update and restart API + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.STAGING_SERVER_IP }} + username: ${{ secrets.STAGING_SERVER_SSH_USERNAME }} + key: ${{ secrets.STAGING_SERVER_SSH_KEY }} + script: "/home/ubuntu/restart.sh" diff --git a/README.md b/README.md index d6d7d8e..de2840c 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # Rezultate Vot API +[![Docker tag](https://img.shields.io/docker/v/code4romania/rezultate-vot-api?style=for-the-badge)](https://hub.docker.com/r/code4romania/rezultate-vot-api/tags) [![GitHub contributors](https://img.shields.io/github/contributors/code4romania/rezultate-vot-api.svg?style=for-the-badge)](https://github.com/code4romania/rezultate-vot-api/graphs/contributors) [![GitHub last commit](https://img.shields.io/github/last-commit/code4romania/rezultate-vot-api.svg?style=for-the-badge)](https://github.com/code4romania/rezultate-vot-api/commits/master) [![License: MPL 2.0](https://img.shields.io/badge/license-MPL%202.0-brightgreen.svg?style=for-the-badge)](https://opensource.org/licenses/MPL-2.0) O democrație se sprijină pe cetățeni critici și informați. Rezultate Vot își propune să informeze și să dezvolte spiritul critic al alegătorilor prin contextualizarea informației electorale însoțite de analize apartinice ale acesteia. Această platformă este locul în care oricine poate accesa toate informațiile relevante ale alegerilor din România. -[See the project live](https://rezultatevot.ro/) +[See the project live](https://rezultatevot.ro) Pe Rezultate Vot veți găsi: + - Hărți detaliate pe care puteți vizualiza prezența la vot la nivelul țării / la nivel de județ; - Rezultatele parțiale ale alegerilor, după închiderea urnelor, pe măsură ce ele sunt comunicate de autorități; - Informații din sistemul de monitorizare digitală a alegerilor - Monitorizare Vot - realizat de Code for Romania și utilizat de observatorii alegerilor @@ -19,11 +21,15 @@ Pe Rezultate Vot veți găsi: This project is built by amazing volunteers and you can be one of them! Here's a list of ways in [which you can contribute to this project](https://github.com/code4romania/.github/blob/master/CONTRIBUTING.md). If you want to make any change to this repository, please **make a fork first**. -If you would like to suggest new functionality, open an Issue and mark it as a __[Feature request]__. Please be specific about why you think this functionality will be of use. If you can, please include some visual description of what you would like the UI to look like, if you are suggesting new UI elements. +If you would like to suggest new functionality, open an Issue and mark it as a **[Feature request]**. Please be specific about why you think this functionality will be of use. If you can, please include some visual description of what you would like the UI to look like, if you are suggesting new UI elements. ## Built With +.net core 3.1 + +### Programming languages +C# 8 ## Repos and projects @@ -31,20 +37,21 @@ Client App - https://github.com/code4romania/rezultate-vot-client ## Deployment -Guide users through getting your code up and running on their own system. In this section you can talk about: -1. Installation process -2. Software dependencies -3. Latest releases -4. API references +### Stage + +Every push to develop branch should trigger a new deploy on stage server + +### Production -Describe and show how to build your code and run the tests. +1. Add a new tag to the repository +2. Go to the [Code4ro k8s manifest repo](https://github.com/code4romania/code4ro-k8s) and update the k8s manifest with the new image tag ## Feedback -* Request a new feature on GitHub. -* Vote for popular feature requests. -* File a bug in GitHub Issues. -* Email us with other feedback contact@code4.ro +- Request a new feature on GitHub. +- Vote for popular feature requests. +- File a bug in GitHub Issues. +- Email us with other feedback contact@code4.ro ## License