Skip to content

Commit

Permalink
Docker production build optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzen authored and chappjc committed Feb 23, 2023
1 parent 28063b2 commit 89942f0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 21 deletions.
41 changes: 20 additions & 21 deletions .github/workflows/release-docker.yml
Expand Up @@ -5,31 +5,30 @@ on:
types: [created]

env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_CLI_EXPERIMENTAL: enabled
IMAGE_NAME: decred/dcrdex

jobs:
build-and-push:
runs-on: ubuntu-22.04

steps:
- name: Checkout code
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c #v3.3.0

- name: Set up Docker Buildx
run: |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --use --name mybuilder
docker buildx inspect --bootstrap
- name: Log in to Docker
run: |
docker login -u ${{ env.DOCKER_USERNAME }} -p ${{ env.DOCKER_PASSWORD }}
- name: Build and Push Docker Image
run: |
docker buildx build -f client/Dockerfile --platform linux/arm64,linux/amd64 \
--tag ${{ env.IMAGE_NAME }}:${{ github.ref_name }} \
--output "type=registry" .
env:
DOCKER_USERNAME: ${{ env.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ env.DOCKER_PASSWORD }}
- name: Login to Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

- name: Checkout project
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c #v3.3.0

- name: Set up QEMU
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 #v2.1.0

- name: Setup Docker buildx action
uses: docker/setup-buildx-action@f03ac48505955848960e80bbb68046aa35c7b9e7 #v2.4.1

- name: Build and Push Docker Image
run: |
docker buildx build \
-f client/Dockerfile.release \
--platform linux/arm64,linux/amd64 \
--tag ${{ env.IMAGE_NAME }}:${{ github.ref_name }} \
--output "type=registry" .
34 changes: 34 additions & 0 deletions client/Dockerfile.release
@@ -0,0 +1,34 @@
#
# Build a release Docker image
# This file is used to build production images off of a release-vx.x branch
# where the site build is checked in. (This allows for faster image builds.)
#
# $ docker build -t user/dcrdex -f client/Dockerfile.release .
#
# Create docker volume to store client data
# $ docker volume create --name=dcrdex_data
#
# Run the docker image, mapping web access port.
# $ docker run -d --rm -p 127.0.0.1:5758:5758 -v dcrdex_data:/dex/.dexc user/dcrdex
#

# dexc binary build
FROM golang:1.20-alpine AS gobuilder
WORKDIR /root/dex
COPY . .
WORKDIR /root/dex/client/cmd/dexc/
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build
WORKDIR /root/dex/client/cmd/dexcctl/
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build

# Final image
FROM debian:buster-slim
RUN apt-get update && apt-get install -y ca-certificates
WORKDIR /dex
ENV HOME /dex
RUN mkdir -p /dex/.dexc && chown 1000 /dex/.dexc
USER 1000
COPY --from=gobuilder /root/dex/client/cmd/dexc/dexc ./
COPY --from=gobuilder /root/dex/client/cmd/dexcctl/dexcctl ./
EXPOSE 5758
CMD [ "./dexc", "--webaddr=0.0.0.0:5758" ]

0 comments on commit 89942f0

Please sign in to comment.