From 3cd59e0b9f5196119e64e7477f6cf5ef1f224d05 Mon Sep 17 00:00:00 2001 From: burakcankazim Date: Tue, 9 Nov 2021 23:14:53 +0300 Subject: [PATCH 1/9] Update backend.yml --- .github/workflows/backend.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index eb08970a..3cb42771 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -38,6 +38,9 @@ jobs: deploy: runs-on: ubuntu-latest needs: publish + defaults: + run: + working-directory: ./application/backend steps: - name: Configure AWS credentials From 22c32c28b118083b91b9eee52492c98f103dad4f Mon Sep 17 00:00:00 2001 From: burakcankazim Date: Tue, 9 Nov 2021 23:16:43 +0300 Subject: [PATCH 2/9] Update backend.yml --- .github/workflows/backend.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 3cb42771..e65d567f 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -13,7 +13,10 @@ on: jobs: publish: runs-on: ubuntu-latest - + defaults: + run: + working-directory: ./application/backend + steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Checkout @@ -38,10 +41,7 @@ jobs: deploy: runs-on: ubuntu-latest needs: publish - defaults: - run: - working-directory: ./application/backend - + steps: - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 From bc9b507fe52a0820e51f2319ee8bcfc74126055f Mon Sep 17 00:00:00 2001 From: burakcankazim Date: Tue, 9 Nov 2021 23:25:04 +0300 Subject: [PATCH 3/9] Update backend.yml --- .github/workflows/backend.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index e65d567f..12af6ae0 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -21,6 +21,8 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Checkout uses: actions/checkout@v2 + with: + ref: dev/backend - name: Setup JDK uses: actions/setup-java@v2.3.1 with: From 8975e244edf3f6eed82abc70d03c207ef49bbd02 Mon Sep 17 00:00:00 2001 From: burakcankazim Date: Tue, 9 Nov 2021 23:27:00 +0300 Subject: [PATCH 4/9] Update backend.yml --- .github/workflows/backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 12af6ae0..b106d72c 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -30,7 +30,7 @@ jobs: distribution: 'temurin' cache: 'gradle' - name: Build image - run: ./application/backend/gradlew bootBuildImage + run: ./gradlew bootBuildImage - name: Docker login uses: docker/login-action@v1.10.0 with: From 2dbb4011983f4ff81cea6f5353b9042696dfc50e Mon Sep 17 00:00:00 2001 From: burakcankazim Date: Sun, 14 Nov 2021 19:59:48 +0300 Subject: [PATCH 5/9] Add ec2 deployment --- .github/workflows/backend.yml | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index b106d72c..907a6e56 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -43,13 +43,25 @@ jobs: deploy: runs-on: ubuntu-latest needs: publish - + defaults: + run: + working-directory: ./application + steps: - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ secrets.AWS_REGION }} - -# TODO Waiting for AWS registaration to cmoplete. + - name: Write the SSH key to a temp file + run: echo ${{ secrets.SSH_KEY }} > temp.pem + + - name: Copy docker-compose.yml into to EC2 instance with SCP. + run: scp -i ./temp.pem ./docker-compose.yml ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }} + + - name: Login to Docker Hub at EC2 instance + run: ssh -i ./temp.pem ./docker-compose.yml ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}" + + - name: Down currently running BeABee application + run: ssh -i ./temp.pem ./docker-compose.yml ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "docker-compose do + + - name: Run services with Docker Compose + run: ssh -i ./temp.pem ./docker-compose.yml ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "docker-compose up" + + - name: Delete temp key file + run: rm temp.pem From 7b4c5786272f0081c64f0a32991b09f156921722 Mon Sep 17 00:00:00 2001 From: burakcankazim Date: Sun, 14 Nov 2021 22:44:47 +0300 Subject: [PATCH 6/9] Building with a Dockerfile instead of Gradle Gradle docker image builder does not work with limited memory in the ec2 instance --- .github/workflows/backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 907a6e56..7680429d 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -30,7 +30,7 @@ jobs: distribution: 'temurin' cache: 'gradle' - name: Build image - run: ./gradlew bootBuildImage + run: ./docker build . -t beabee/beabee_spring - name: Docker login uses: docker/login-action@v1.10.0 with: From bdc2568c6cda07dc44a17c289f8a435c0c49ef43 Mon Sep 17 00:00:00 2001 From: burakcankazim Date: Sun, 14 Nov 2021 23:29:49 +0300 Subject: [PATCH 7/9] fix typo --- .github/workflows/backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 7680429d..6efefe3f 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -30,7 +30,7 @@ jobs: distribution: 'temurin' cache: 'gradle' - name: Build image - run: ./docker build . -t beabee/beabee_spring + run: docker build . -t beabee/beabee_spring - name: Docker login uses: docker/login-action@v1.10.0 with: From f9e8937ff5838aa783c2f61363b543382e4dd210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burakcan=20Ye=C5=9Fil?= Date: Mon, 15 Nov 2021 00:20:08 +0300 Subject: [PATCH 8/9] ci-cd(backend): Added Dockerfile and docker-compose.yml for the backend server #248 --- application/backend/Dockerfile | 3 +++ application/docker-compose.yml | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 application/backend/Dockerfile create mode 100644 application/docker-compose.yml diff --git a/application/backend/Dockerfile b/application/backend/Dockerfile new file mode 100644 index 00000000..700d007a --- /dev/null +++ b/application/backend/Dockerfile @@ -0,0 +1,3 @@ +FROM openjdk:13-alpine +COPY build/libs/beabee-0.0.1-SNAPSHOT.jar app.jar +ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file diff --git a/application/docker-compose.yml b/application/docker-compose.yml new file mode 100644 index 00000000..438aafa5 --- /dev/null +++ b/application/docker-compose.yml @@ -0,0 +1,35 @@ +version: '3' + +services: + db-server: + image: "postgres" + container_name: "db-server" + ports: + - "5432:5432" + environment: + POSTGRES_DB: beabee + POSTGRES_USER: postgres + POSTGRES_PASSWORD: 5432 + networks: + - beabeenw + beabee-server: + image: "beabeeapp/beabee" + container_name: "beabee-server" + ports: + - "8085:8085" + environment: + spring.datasource.url: jdbc:postgresql://db-server:5432/beabee + SPRING_DATASOURCE_USERNAME: postgres + SPRING_DATASOURCE_PASSWORD: 5432 + networks: + - beabeenw + depends_on: + - db-server + restart: always +networks: + beabeenw: + driver: bridge + ipam: + driver: default + config: + - subnet: '10.111.6.0/24' From 45288d2c0ffd2d5b3b794178c088920f1312e306 Mon Sep 17 00:00:00 2001 From: burakcankazim Date: Mon, 15 Nov 2021 01:32:19 +0300 Subject: [PATCH 9/9] Added build jar phase --- .github/workflows/backend.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 6efefe3f..ce2c0f54 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -29,6 +29,9 @@ jobs: java-version: '11' distribution: 'temurin' cache: 'gradle' + + - name: Build jar + run: ./gradlew jar - name: Build image run: docker build . -t beabee/beabee_spring - name: Docker login