From 3e2b40870c408bdd0b0b7468f0b0c3d57545329e Mon Sep 17 00:00:00 2001 From: Quang Le Date: Fri, 15 Sep 2023 13:50:30 +0700 Subject: [PATCH] chore: update dockerfile (#1188) * chore: update dockerfile * chore: update CI --- .github/workflows/ci-test.yml | 28 ++++++++++++++++++++++++++-- Dockerfile | 10 ++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 022c7a877..b0e6de769 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -6,7 +6,7 @@ jobs: # Service containers to run with `container-job` services: - # Label used to access the service container + # pg test postgres: # Docker Hub image image: postgres:15 @@ -22,7 +22,29 @@ jobs: --health-retries 5 ports: - 25433:5432 - + # pg local + postgres_local: + # Docker Hub image + image: postgres:15 + # Provide the password for postgres + env: + POSTGRES_PASSWORD: postgres + POSTGRES_DB: mochi_local + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5434:5432 + # chrome + chrome: + # Docker Hub image + image: browserless/chrome + ports: + - 3000:3000 + # redis redis: image: redis:6 ports: @@ -37,5 +59,7 @@ jobs: go-version-file: go.mod - name: Install run: go install github.com/rubenv/sql-migrate/sql-migrate@latest + - name: Migrate pg local + run: make migrate-up - name: Run Test cases run: make test diff --git a/Dockerfile b/Dockerfile index 7269171c7..581fe5da9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM golang:1.20-alpine +FROM dwarvesf/sql-migrate as sql-migrate + +FROM golang:1.20-alpine as builder RUN mkdir /build WORKDIR /build COPY . . @@ -9,15 +11,15 @@ RUN set -ex && \ apk add --no-progress --no-cache \ gcc \ musl-dev -RUN go install --tags musl -v ./... -RUN go install -v github.com/rubenv/sql-migrate/sql-migrate@latest +RUN go install --tags musl ./... FROM alpine:3.15.0 RUN apk --no-cache add ca-certificates RUN ln -fs /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime WORKDIR / -COPY --from=0 /go/bin/* /usr/bin/ +COPY --from=sql-migrate /usr/local/bin/sql-migrate /usr/bin/ +COPY --from=builder /go/bin/* /usr/bin/ COPY migrations /migrations COPY images /images COPY dbconfig.yml /