Skip to content

Commit

Permalink
chore: simplify development routine using container
Browse files Browse the repository at this point in the history
This commit simplifies the development routing using containers and
shortcuts using Makefile.

The user can start the development environment using the command
`make run-dev` command, which will create and start all the
containers required for Archivista. The significant advantage is that
the user wants to test the container, so it is not necessary to build
Archivista, rebuild the container, and run it. It is done
automatically by CompileDaemon.

This command also includes:
`make stop` to stop all container
`make clean` to clean all Archivista containers

Added a shortcut to run the Archivista tests
`make tests`

This strategy is inspired by
- Warehouse development: https://warehouse.pypa.io/development/getting-started.html#running-the-warehouse-container-and-services
- RSTUF development: https://github.com/repository-service-tuf/repository-service-tuf-api#running-api-development

Signed-off-by: Kairo de Araujo <[email protected]>
  • Loading branch information
kairoaraujo committed Dec 11, 2023
1 parent 92c211c commit 92ab8be
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 The Archivista Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.21.5-alpine@sha256:5c1cabd9a3c6851a3e18735a2c133fbd8f67fe37eb3203318b7af2ffd2547095 AS build
WORKDIR /src
RUN apk update && apk add --no-cache file git
ENV GOMODCACHE /root/.cache/gocache
RUN go install github.com/githubnemo/CompileDaemon@latest
ENTRYPOINT CompileDaemon -log-prefix=false -build="go build -o /out/archivista ./cmd/archivista" -command="/out/archivista"
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2023 The Archivista Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Nothing to be run by default as the CodeQL autobuild tries to run make
# See https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#autobuild-for-go
all: help

run-dev: ## Run the dev server
@echo "Running dev server. It will refresh automatically when you change code."
@docker build -t archivista:dev .
@docker compose -f compose-dev.yml up --remove-orphans


.PHONY: stop
stop: ## Stop the dev server
@docker-compose down -v


.PHONY: clean
clean:
$(MAKE) stop
@docker compose rm --force
@docker rmi archivista-archivista --force


.PHONY: test
test: ## Clean up the dev server
@bash ./test/test.sh

help: ## Show this help
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
80 changes: 80 additions & 0 deletions compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright 2023 The Archivista Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version: '3.9'

services:
db:
image: mysql:oracle
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
- 3306:3306
environment:
MYSQL_DATABASE: testify
MYSQL_ROOT_PASSWORD: example
volumes:
- mysqldata:/var/lib/mysql

archivista:
build:
context: .
dockerfile: ./Dockerfile-dev
restart: unless-stopped
environment:
ARCHIVISTA_LISTEN_ON: tcp://0.0.0.0:8082
ARCHIVISTA_ENABLE_SPIFFE: "false"
ARCHIVISTA_STORAGE_BACKEND: BLOB
ARCHIVISTA_FILE_DIR: /tmp/archivista/
ARCHIVISTA_FILE_SERVE_ON: :8081
ARCHIVISTA_BLOB_STORE_USE_TLS: "false"
ARCHIVISTA_BLOB_STORE_ACCESS_KEY_ID: testifytestifytestify
ARCHIVISTA_BLOB_STORE_SECRET_ACCESS_KEY_ID: exampleexampleexample
ARCHIVISTA_BLOB_STORE_BUCKET_NAME: attestations
ARCHIVISTA_BLOB_STORE_ENDPOINT: minio:9000
ARCHIVISTA_ENABLE_GRAPHQL: "true"
ARCHIVISTA_GRAPHQL_WEB_CLIENT_ENABLE: "true"
ARCHIVISTA_CORS_ALLOW_ORIGINS: "http://localhost:1234"

ports:
- 8081:8081
- 8082:8082
volumes:
- fileserver:/tmp/archivista
- ./:/src

minio:
image: quay.io/minio/minio
restart: always
command: server /data --console-address ":9001"
ports:
- 9000:9000
- 9001:9001
environment:
MINIO_ROOT_USER: testifytestifytestify
MINIO_ROOT_PASSWORD: exampleexampleexample
volumes:
- miniodata:/data

minio-init:
image: quay.io/minio/mc
restart: on-failure
command: mb --insecure --ignore-existing testminio/attestations
environment:
MC_HOST_testminio: http://testifytestifytestify:exampleexampleexample@minio:9000

volumes:
fileserver:
miniodata:
mysqldata:

0 comments on commit 92ab8be

Please sign in to comment.