Skip to content

Commit

Permalink
CD test
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeMaster482 committed Nov 9, 2023
1 parent 87a9689 commit ed4caa5
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 178 deletions.
30 changes: 20 additions & 10 deletions .github/workflows/CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CD

env:
REGISTRY: "codemaster482"
IMAGE_NAME: "HammyWallet-Server"
IMAGE_NAME: "hammywallet"
CONTAINER_NAME: "HammyWallet-API"
FOLDER_COMPOSE: "backend/2023_2_Hamster"

Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.GITHUB_SHA_SHORT }}, ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
file: ./build/Dockerfile.multistage.main
file: ./build/Dockerfile
build-args: |
IMAGE_NAME=${{ env.IMAGE_NAME }}
REGISTRY=${{ env.REGISTRY }}
Expand Down Expand Up @@ -100,19 +100,29 @@ jobs:
sudo bash
cd $(echo $FOLDER_COMPOSE)
# Make .env variables file
cat <<EOF>.env
POSTGRES_DB=${{ secrets.POSTGRES_DB }}
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
DB_NAME=${{ secrets.DB_NAME }}
DB_USER=${{ secrets.POSTGRES_USER }}
DB_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
DB_HOST=${{ secrets.DB_HOST }}
DB_PORT=${{ secrets.DB_PORT }}
POSTGRES_USER=${{ secrets.POSTGRES_USER }}
PGADMIN_DEFAULT_EMAIL=${{ secrets.PGADMIN_DEFAULT_EMAIL }}
PGADMIN_DEFAULT_PASSWORD=${{ secrets.PGADMIN_DEFAULT_PASSWORD }}
JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}
SECRET=${{ secrets.SECRET }}
IMAGE_NAME=${{ env.IMAGE_NAME }}
REGISTRY=${{ env.REGISTRY }}
CONTAINER_NAME=${{ env.CONTAINER_NAME }}
EOF
EOF
echo "GITHUB_SHA_SHORT=`echo $GITHUB_SHA | head -c8`" >> .env
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
docker pull $REGISTRY/$IMAGE_NAME:latest
docker system prune -f
docker compose down
docker compose up -d
4 changes: 2 additions & 2 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
go-version: '1.21.x'

- name: Cache Go modules
uses: actions/cache@v3
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
go-version: '1.21.x'

- name: Install dependencies
run: go mod tidy
Expand Down
136 changes: 0 additions & 136 deletions .github/workflows/config.yaml

This file was deleted.

22 changes: 17 additions & 5 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
FROM golang:latest
COPY . /app
WORKDIR /app
FROM golang:1.21.0-alpine AS build

COPY . /github.com/go-park-mail-ru/2023_2_Hamster/
WORKDIR /github.com/go-park-mail-ru/2023_2_Hamster/

RUN go mod download
RUN go build -o app ./cmd/api/main.go
ENTRYPOINT ["./app"]
RUN go clean --modcache
RUN go build -mod=readonly -o ./.server ./cmd/api/main.go

FROM scratch AS run

WORKDIR /docker-HammyWallet/

COPY --from=builder /github.com/go-park-mail-ru/2023_2_Hamster/.server .

EXPOSE 80 433

ENTRYPOINT ["./server"]
51 changes: 26 additions & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,8 @@ networks:
driver: bridge

services:

server:
container_name: ${SERVER_NAME_PROD}
build:
context: .
dockerfile: ./build/Dockerfile
restart: on-failure
networks:
- app-network
ports:
- "8080:8080"
depends_on:
- postgres
- redis
env_file:
- .env

postgres:
container_name: ${DB_CONTAINER_NAME}
hammy-postgres:
container_name: hammy-postgres
image: postgres:latest
restart: on-failure
env_file:
Expand Down Expand Up @@ -59,11 +42,11 @@ services:
- "-c"
- "pg_stat_statements.track=all"
ports:
- "5436:5432"
- "${DB_PORT}:5432"
environment:
POSTGRES_DB: ${DB_NAME_PROD}
POSTGRES_USER: ${DB_USER_PROD}
POSTGRES_PASSWORD: ${DB_PASSWORD_PROD}
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- ./cmd/api/init/db/postgresql/schema/:/docker-entrypoint-initdb.d/
healthcheck:
Expand All @@ -75,11 +58,29 @@ services:
networks:
- app-network

redis:
container_name: ${REDIS_CONTAINER_NAME}

hammy-redis:
container_name: hammy-redis
image: redis:latest
restart: on-failure
networks:
- app-network
ports:
- "6379:6379"


hammywallet-api:
container_name: hammywallet-api
env_file:
- .env
build:
context: .
dockerfile: ./build/Dockerfile
restart: on-failure
ports:
- "8080:8080"
depends_on:
- postgres
- redis
networks:
- app-network

0 comments on commit ed4caa5

Please sign in to comment.