diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb5bda1..7815c31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -175,6 +175,21 @@ jobs: uses: actions/download-artifact@v2 with: name: poseidon + - name: Get current branch name + id: branch-name + uses: tj-actions/branch-names@v6 + - name: Checkout matching branch for Dockerfiles (optional) + id: checkout-dockerfiles + if: steps.branch-name.outputs.is_default == 'false' + uses: actions/checkout@v3 + continue-on-error: true + with: + repository: openHPI/dockerfiles + path: deploy/dockerfiles + ref: ${{ steps.branch-name.outputs.current_branch }} + - name: Build new e2e test image (optional) + if: steps.checkout-dockerfiles.outcome == 'success' + run: make e2e-test-docker-image - name: Run e2e tests run: | sudo ./nomad agent -dev -log-level=WARN -config e2e-config.hcl & diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 31bcd22..e2a4d23 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -51,16 +51,3 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - - name: Extract metadata (tags, labels) for Docker e2e image - id: e2e-meta - uses: docker/metadata-action@v3 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-e2e-tests - - name: Build and push e2e Docker image - uses: docker/build-push-action@v2 - with: - context: . - file: deploy/e2e-test-image/Dockerfile - push: true - tags: ${{ steps.e2e-meta.outputs.tags }} - labels: ${{ steps.e2e-meta.outputs.labels }} diff --git a/.gitignore b/.gitignore index 7939883..0f2bb3c 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ tests/e2e/configuration.yaml # IDE files /.idea *.iml + +# Dockerfiles repository +deploy/dockerfiles diff --git a/Makefile b/Makefile index f9115dd..9dfc525 100644 --- a/Makefile +++ b/Makefile @@ -3,13 +3,14 @@ REPOSITORY_OWNER = "openHPI" PKG := "github.com/$(REPOSITORY_OWNER)/$(PROJECT_NAME)/cmd/$(PROJECT_NAME)" UNIT_TESTS = $(shell go list ./... | grep -v /e2e) -DOCKER_E2E_CONTAINER_NAME := "$(PROJECT_NAME)-e2e-tests" DOCKER_TAG := "poseidon:latest" DOCKER_OPTS := -v $(shell pwd)/configuration.yaml:/configuration.yaml LOWER_REPOSITORY_OWNER = $(shell echo $(REPOSITORY_OWNER) | tr A-Z a-z) -REGISTRY = "ghcr.io" -TAG = ":main" -E2E_TEST_DOCKER_IMAGE = "$(REGISTRY)/$(LOWER_REPOSITORY_OWNER)/$(DOCKER_E2E_CONTAINER_NAME)$(TAG)" + +# Define image to be used in e2e tests. Requires `make` to be available. +E2E_TEST_DOCKER_CONTAINER := co_execenv_java +E2E_TEST_DOCKER_TAG := 17 +E2E_TEST_DOCKER_IMAGE = "$(LOWER_REPOSITORY_OWNER)/$(E2E_TEST_DOCKER_CONTAINER):$(E2E_TEST_DOCKER_TAG)" default: help @@ -92,24 +93,27 @@ coverage: deps ## Generate code coverage report coverhtml: coverage ## Generate HTML coverage report @go tool cover -html=coverage_cleaned.cov -o coverage_unit.html -.PHONY: e2e-test-docker-image ## Build Docker image that is pushed to a registry and used in e2e tests -e2e-test-docker-image: deploy/e2e-test-image/Dockerfile - @docker build -t $(E2E_TEST_DOCKER_IMAGE) deploy/e2e-test-image +deploy/dockerfiles: ## Clone Dockerfiles repository + @git clone git@github.com:$(REPOSITORY_OWNER)/dockerfiles.git deploy/dockerfiles + +.PHONY: e2e-test-docker-image +e2e-test-docker-image: deploy/dockerfiles ## Build Docker image that is pushed to a registry and used in e2e tests + @docker build -t $(E2E_TEST_DOCKER_IMAGE) deploy/dockerfiles/$(E2E_TEST_DOCKER_CONTAINER)/$(E2E_TEST_DOCKER_TAG) .PHONY: e2e-test e2e-test: deps ## Run e2e tests - @docker pull $(E2E_TEST_DOCKER_IMAGE) + @[ -z "$(docker images -q $(E2E_TEST_DOCKER_IMAGE))" ] || docker pull $(E2E_TEST_DOCKER_IMAGE) @go test -count=1 ./tests/e2e -v -args -dockerImage="$(E2E_TEST_DOCKER_IMAGE)" .PHONY: e2e-docker e2e-docker: docker ## Run e2e tests against the Docker container docker run --rm -p 127.0.0.1:7200:7200 \ - --name $(DOCKER_E2E_CONTAINER_NAME) \ + --name $(E2E_TEST_DOCKER_CONTAINER) \ -e POSEIDON_SERVER_ADDRESS=0.0.0.0 \ $(DOCKER_OPTS) \ $(DOCKER_TAG) & @timeout 30s bash -c "until curl -s -o /dev/null http://127.0.0.1:7200/; do sleep 0.1; done" - @make e2e-test || EXIT=$$?; docker stop $(DOCKER_E2E_CONTAINER_NAME); exit $$EXIT + @make e2e-test || EXIT=$$?; docker stop $(E2E_TEST_DOCKER_CONTAINER); exit $$EXIT # See https://aquasecurity.github.io/trivy/v0.18.1/integrations/gitlab-ci/ TRIVY_VERSION = $(shell wget -qO - "https://api.github.com/repos/aquasecurity/trivy/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/') diff --git a/deploy/e2e-test-image/Dockerfile b/deploy/e2e-test-image/Dockerfile deleted file mode 100644 index 03a9d2e..0000000 --- a/deploy/e2e-test-image/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -# Minimal working Docker image used in our e2e tests -FROM python:latest - -RUN useradd --home-dir /workspace --no-create-home --user-group user && \ - mkdir /workspace && chown user:user /workspace - -WORKDIR /workspace - -USER user