I have docker-compose.yml that looks like this:
version: '3.5'
volumes:
postgres_volume:
networks:
product_catalog_network:
external: true
services:
pg:
build:
context: .
dockerfile: postgres.Dockerfile
image: "<someregistry_url>/postgres:14-alpine"
env_file:
- .env
healthcheck:
test: ["CMD", "pg_isready"]
ports:
- "5432:5432"
networks:
- product_catalog_network
product-catalog-service:
restart: always
build: .
image: "<someregistry_url>/product-catalog-service:latest"
depends_on:
- pg
ports:
- "${GRPC_PORT:-5001}:${GRPC_PORT:-5001}"
- "${HTTP_PORT:-8080}:${HTTP_PORT:-8080}"
- "${SWAGGER_PORT:-8090}:${SWAGGER_PORT:-8090}"
networks:
- product_catalog_network
migrator:
build:
context: .
dockerfile: migration.Dockerfile
image: "<someregistry_url>/migrator:latest"
restart: on-failure
env_file:
- .env
networks:
- product_catalog_network
My Dockerfile for product-catalog-service:
FROM golang:1.22-alpine AS builder
RUN apk update && apk upgrade &&
apk add --no-cache git
RUN mkdir /app
WORKDIR /app
ENV GO111MODULE=on
COPY . .
RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o product-service ./cmd/main.go
FROM alpine:latest
RUN apk --no-cache add ca-certificates
RUN mkdir /app
WORKDIR /app
COPY .env .
COPY --from=builder /app/product-service .
CMD ["./product-service"]
My migration.Dockerfile:
FROM alpine:3.13
RUN apk update &&
apk upgrade &&
apk add bash &&
rm -rf /var/cache/apk/*
ADD https://github.com/pressly/goose/releases/download/v3.14.0/goose_linux_x86_64 /bin/goose
RUN chmod +x /bin/goose
WORKDIR /root
ADD migrations/*.sql migrations/
ADD migration.sh .
ADD .env .
RUN chmod +x migration.sh
ENTRYPOINT ["bash", "migration.sh"]
My postgres.Dockerfile:
FROM postgres:14-alpine
EXPOSE 5432
USER postgres
Now I need to build all this docker images and push them to my registry. I’m doing it like this with GitHub Actions:
name: Go
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
image-build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
registry: ${{ secrets.REGISTRY_URL }}
- name: Build and push Docker images
run: |
echo "${{ secrets.ENV_DEVELOPMENT }}" > .env
docker-compose build
docker-compose push
After that I need to deploy all my docker images to the remote host. I need to extract them from the registry and run them all. How should I do this? Do I have to manually pull all the images from the registry and run them individually via docker run? Or should I clone my repository with docker-compose.yml and do docker compose pull, docker compose build and docker compose up -d through it already? Or is there some other option that is more preferable?