Skip to content

Commit

Permalink
move backend into main repo (#931)
Browse files Browse the repository at this point in the history
* move backend into main repo
  • Loading branch information
motatoes authored Dec 19, 2023
1 parent bba20b5 commit ce90a0f
Show file tree
Hide file tree
Showing 75 changed files with 12,846 additions and 18 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/backend_build_prod_ecr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Backend Build&Push to Prod ECR
on:
push:
branches: [ 'develop' ]

permissions:
id-token: write
contents: read

jobs:
build:
name: Build Image
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.PROD_AWS_ROLE }}
aws-region: eu-west-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: cloud-web
IMAGE_TAG: latest
run: |
export COMMIT_SHA=$(git rev-parse --short HEAD)
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --build-arg COMMIT_SHA=${COMMIT_SHA} -f backend/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
working-directory: backend

restart:
needs: build
name: Restart ECS service
runs-on: ubuntu-latest

steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.PROD_AWS_ROLE}}
aws-region: eu-west-2

- name: Restart ECS
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
AWS_REGION: eu-west-2
run: |
aws ecs update-service --cluster ${{ vars.ECS_CLUSTER_NAME }} --service ${{ vars.ECS_SERVICE_NAME }} --force-new-deployment --region $AWS_REGION
57 changes: 57 additions & 0 deletions .github/workflows/backend_build_test_ecr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Backend Build&Push to Test ECR
on:
push:
branches: [ 'develop', 'feat/*' ]

permissions:
id-token: write
contents: read

jobs:
build:
name: Build Image
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.TEST_AWS_ROLE }}
aws-region: eu-west-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: cloud-web
IMAGE_TAG: latest
run: |
export COMMIT_SHA=$(git rev-parse --short HEAD)
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --build-arg COMMIT_SHA=${COMMIT_SHA} .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
working-directory: backend

restart:
needs: build
name: Restart ECS service
runs-on: ubuntu-latest

steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.TEST_AWS_ROLE}}
aws-region: us-east-1

- name: Restart ECS
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
AWS_REGION: eu-west-2
run: |
aws ecs update-service --cluster ${{ vars.ECS_CLUSTER_NAME }} --service ${{ vars.ECS_SERVICE_NAME }} --force-new-deployment --region $AWS_REGION
41 changes: 41 additions & 0 deletions .github/workflows/backend_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Backend release
on:
release:
types: [released]
jobs:
binary:
strategy:
matrix:
arch: [arm, arm64, amd64, 386]
os: [linux, darwin, freebsd, windows]
exclude:
- os: darwin
arch: arm
- os: darwin
arch: 386

runs-on: ubuntu-latest
steps:
- name: Download Go
uses: actions/setup-go@v4
with:
go-version: 1.21.1
id: go

- name: Check out repository
uses: actions/checkout@v4
- name: Build
run: |
echo "Tag that is going to be used as digger version: ${{ github.event.release.tag_name }}"
env GOOS=${{matrix.os}} GOARCH=${{matrix.arch}} CGO_ENABLED=0 go build -ldflags="-X digger/pkg/utils.version=${{ github.event.release.tag_name }}" -o digger-api ./
- name: Publish linux-x64 exec to github
id: upload-release-asset-linux-x64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: 'digger-api'
asset_name: digger-api-${{matrix.os}}-${{matrix.arch}}
asset_content_type: application/octet-stream

35 changes: 35 additions & 0 deletions .github/workflows/backend_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Backend Go Tests
on:
push:
branches: [ develop ]
pull_request:

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Download Go
uses: actions/setup-go@v4
with:
go-version: 1.21.1
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Deps
run: go get -v ./...
working-directory: backend

- name: Build
run: go build
working-directory: backend

- name: Test
run: go test -v ./...
env:
GITHUB_PAT_TOKEN: ${{ secrets.TOKEN_GITHUB }}
working-directory: backend
2 changes: 2 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dockerfile
cloud
12 changes: 12 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
backend
.idea/
.DS_Store
venv/
**/__pycache__/
__azurite*
./digger
cloud
*.env
*.env.*
.docker-compose-env
controllers/database_test.db
41 changes: 41 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM golang:1.21 as builder
ARG COMMIT_SHA
RUN echo "commit sha: ${COMMIT_SHA}"

# Set the working directory
WORKDIR $GOPATH/src/github.com/diggerhq/digger/backend

# Copy all required source, blacklist files that are not required through `.dockerignore`
COPY . .

# Get the vendor library
RUN go version

# RUN vgo install

# https://github.com/ethereum/go-ethereum/issues/2738
# Build static binary "-getmode=vendor" does not work with go-ethereum
RUN go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o backend

# Multi-stage build will just copy the binary to an alpine image.
FROM ubuntu:22.04 as runner
ARG COMMIT_SHA
WORKDIR /app

RUN apt-get update && apt-get install -y ca-certificates && apt-get install -y git && apt-get clean all
RUN update-ca-certificates

RUN echo "commit sha: ${COMMIT_SHA}"

# Set gin to production
#ENV GIN_MODE=release

# Expose the running port
EXPOSE 3000

# Copy the binary to the corresponding folder
COPY --from=builder /go/src/github.com/diggerhq/digger/backend/backend .
ADD templates ./templates

# Run the binary
CMD ["/app/backend"]
Loading

0 comments on commit ce90a0f

Please sign in to comment.