Skip to content

Commit

Permalink
Enhances the image build process and refactors the workflows (#25)
Browse files Browse the repository at this point in the history
* chore(CI/CD): Refactors the Docker image build process and CI/CD workflows

* chore(SemVer): Release to 1.3.0

* chore(SemVer): Release to 1.3.0

---------

Co-authored-by: Bogdan Vidrean <bogdan.vidrean@olx.com>
  • Loading branch information
BogdanVidrean and Bogdan Vidrean committed Mar 22, 2023
1 parent 425de6d commit 4b6f0d1
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 201 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/build.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/pull-requests-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: pull-request-tests

on:
pull_request:
branches:
- master
push:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
container: rust:1.66.1-alpine3.17
services:
backend:
image: nginx:latest
options: -v ${{ github.workspace }}/tests/resources/:/usr/share/nginx/html/ --name backend
steps:
- uses: actions/checkout@v2
- name: Restart nginx
uses: docker://docker
with:
args: docker restart backend
- uses: Swatinem/rust-cache@v1
- name: Install libvips
run: apk add --update --no-cache
--repository https://dl-cdn.alpinelinux.org/alpine/v3.17/community
--repository https://dl-cdn.alpinelinux.org/alpine/v3.17/main
curl
musl-dev=1.2.3-r4
vips-dev=8.13.3-r1
vips-heif=8.13.3-r1
- name: Check if nginx is available for files hosting
run: curl http://backend/exif --output /dev/null
- name: Build Dali
run: RUSTFLAGS="-C target-feature=-crt-static $(pkg-config vips --libs)" cargo build
- name: Run Dali
run: ./target/debug/dali >> /dev/null &
- name: Check if Dali is running
run: sleep 5 && nc -z localhost 8080
- name: Run tests
run: RUSTFLAGS="-C target-feature=-crt-static $(pkg-config vips --libs)" HTTP_HOST=backend cargo test
- name: Exit with the test result
run: exit $?
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# (c) Copyright 2019-2023 OLX
name: build-base-images

name: build

on:
push:
branches:
- master
paths:
- Dockerfile.base
- Dockerfile.vips
- Makefile
- .github/workflows/base_image.yml

- Cargo.toml
jobs:
build_base_docker_image:
publish_docker_image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Docker login
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build and Publish to GPR
run: make build-base-image
run: make docker-publish
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (c) Copyright 2019-2023 OLX
[package]
name = "dali"
version = "1.2.0"
version = "1.3.0"
authors = ["Augusto César Dias <augusto.dias@olx.com>"]
edition = "2018"

Expand Down
26 changes: 17 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# (c) Copyright 2019-2023 OLX
ARG BUILD_IMAGE=ghcr.io/olxgroup-oss/dali/base-rust-image
ARG BASE_IMAGE=ghcr.io/olxgroup-oss/dali/base-dali

FROM ${BUILD_IMAGE}:latest as build
FROM rust:1.66.1-alpine3.17 as build

WORKDIR /usr/src/dali
RUN apk add --update --no-cache \
--repository https://dl-cdn.alpinelinux.org/alpine/v3.17/community \
--repository https://dl-cdn.alpinelinux.org/alpine/v3.17/main \
musl-dev=1.2.3-r4 \
vips-dev=8.13.3-r1

COPY . .

# this flag ensures that proc macro can be compiled in musl targets
RUN RUSTFLAGS="-C target-feature=-crt-static $(pkg-config vips --libs)" cargo install --path .
RUN RUSTFLAGS="-C target-feature=-crt-static $(pkg-config vips --libs)" cargo build --release

FROM alpine:3.17.2

FROM ${BASE_IMAGE}:latest
RUN apk add --update --no-cache \
--repository https://dl-cdn.alpinelinux.org/alpine/v3.17/community \
--repository https://dl-cdn.alpinelinux.org/alpine/v3.17/main \
vips=8.13.3-r1 \
vips-heif=8.13.3-r1 \
openssl=3.0.8-r0

COPY --from=build /usr/local/cargo/bin/dali /usr/local/bin/dali
COPY --from=build /usr/src/dali/target/release/dali /usr/local/bin/dali

CMD dali
CMD ["dali"]
37 changes: 0 additions & 37 deletions Dockerfile.base

This file was deleted.

43 changes: 0 additions & 43 deletions Dockerfile.vips

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2019-2020 OLX
Copyright 2019-2023 OLX

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
44 changes: 13 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,27 @@
# (c) Copyright 2019-2023 OLX
DOCKER_REGISTRY ?= ghcr.io
DOCKER_ORG ?= olxgroup-oss
BUILD_IMAGE ?= $(DOCKER_REGISTRY)/$(DOCKER_ORG)/dali/base-rust-image
BASE_IMAGE ?= $(DOCKER_REGISTRY)/$(DOCKER_ORG)/dali/base-dali
RUNTIME_IMAGE ?= $(DOCKER_REGISTRY)/$(DOCKER_ORG)/dali/dali
DALI_IMAGE_NAME ?= $(DOCKER_REGISTRY)/$(DOCKER_ORG)/dali/dali
BUILD_NUMBER ?= $(shell ./scripts/get-current-version.sh)

PROJECT_NAME=dali

REVISION ?= $(shell git rev-parse --short HEAD)
ifeq ($(BUILD_NUMBER),)
VERSION_TAG ?= $(REVISION)
ifeq ($(REVISION),)
VERSION_TAG ?= $(BUILD_NUMBER)
else
VERSION_TAG ?= $(REVISION)-$(BUILD_NUMBER)
VERSION_TAG ?= $(REVISION)-preview
endif

SUDO := $(shell docker info >/dev/null 2>&1 || echo sudo)

.PHONY: up test build-base-image build-image

up:
RUNTIME_IMAGE=$(RUNTIME_IMAGE) $(SUDO) docker-compose -p $(PROJECT_NAME) \
-f docker-compose.yaml \
up --remove-orphans --exit-code-from dali

test:
RUNTIME_IMAGE=$(RUNTIME_IMAGE) BUILD_IMAGE=$(BUILD_IMAGE) $(SUDO) docker-compose -p $(PROJECT_NAME) \
-f docker-compose.yaml -f docker-compose.tests.yaml \
up --no-recreate --remove-orphans --exit-code-from cargo
./scripts/dali-tests-runner.sh

run:
cargo run

build-base-image:
$(SUDO) docker build -f Dockerfile.base -t "$(BUILD_IMAGE):$(VERSION_TAG)" .
$(SUDO) docker build -f Dockerfile.vips -t "$(BASE_IMAGE):$(VERSION_TAG)" .
$(SUDO) docker tag "$(BUILD_IMAGE):$(VERSION_TAG)" "$(BUILD_IMAGE):latest"
$(SUDO) docker push "$(BUILD_IMAGE):$(VERSION_TAG)"
$(SUDO) docker push "$(BUILD_IMAGE):latest"
$(SUDO) docker tag "$(BASE_IMAGE):$(VERSION_TAG)" "$(BASE_IMAGE):latest"
$(SUDO) docker push "$(BASE_IMAGE):$(VERSION_TAG)"
$(SUDO) docker push "$(BASE_IMAGE):latest"
docker-build:
docker build -t ${DALI_IMAGE_NAME}:${VERSION_TAG} .

build-image:
$(SUDO) docker build --build-arg BASE_IMAGE=$(BASE_IMAGE) --build-arg BUILD_IMAGE=$(BUILD_IMAGE) -t "$(RUNTIME_IMAGE):$(VERSION_TAG)" .
$(SUDO) docker tag "$(RUNTIME_IMAGE):$(VERSION_TAG)" "$(RUNTIME_IMAGE):latest"
$(SUDO) docker push "$(RUNTIME_IMAGE):$(VERSION_TAG)"
$(SUDO) docker push "$(RUNTIME_IMAGE):latest"
docker-publish: docker-build
docker push ${DALI_IMAGE_NAME}:${VERSION_TAG}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ Watermarks is an array parameter and therefore, must be indexed when informed (0

## License

(c) Copyright 2019-2020 [OLX](https://olxgroup.com). Released under [Apache 2 License](LICENSE)
(c) Copyright 2019-2023 [OLX](https://olxgroup.com). Released under [Apache 2 License](LICENSE)
23 changes: 0 additions & 23 deletions docker-compose.tests.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions docker-compose.yaml

This file was deleted.

Loading

0 comments on commit 4b6f0d1

Please sign in to comment.