Use local Docker image in e2e pipeline and rebuild image if necessary

This commit is contained in:
Sebastian Serth
2022-09-18 01:51:50 +02:00
committed by Sebastian Serth
parent 7454e577e4
commit 69237fb415
5 changed files with 32 additions and 32 deletions

View File

@ -175,6 +175,21 @@ jobs:
uses: actions/download-artifact@v2 uses: actions/download-artifact@v2
with: with:
name: poseidon 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 - name: Run e2e tests
run: | run: |
sudo ./nomad agent -dev -log-level=WARN -config e2e-config.hcl & sudo ./nomad agent -dev -log-level=WARN -config e2e-config.hcl &

View File

@ -51,16 +51,3 @@ jobs:
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} 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 }}

3
.gitignore vendored
View File

@ -16,3 +16,6 @@ tests/e2e/configuration.yaml
# IDE files # IDE files
/.idea /.idea
*.iml *.iml
# Dockerfiles repository
deploy/dockerfiles

View File

@ -3,13 +3,14 @@ REPOSITORY_OWNER = "openHPI"
PKG := "github.com/$(REPOSITORY_OWNER)/$(PROJECT_NAME)/cmd/$(PROJECT_NAME)" PKG := "github.com/$(REPOSITORY_OWNER)/$(PROJECT_NAME)/cmd/$(PROJECT_NAME)"
UNIT_TESTS = $(shell go list ./... | grep -v /e2e) UNIT_TESTS = $(shell go list ./... | grep -v /e2e)
DOCKER_E2E_CONTAINER_NAME := "$(PROJECT_NAME)-e2e-tests"
DOCKER_TAG := "poseidon:latest" DOCKER_TAG := "poseidon:latest"
DOCKER_OPTS := -v $(shell pwd)/configuration.yaml:/configuration.yaml DOCKER_OPTS := -v $(shell pwd)/configuration.yaml:/configuration.yaml
LOWER_REPOSITORY_OWNER = $(shell echo $(REPOSITORY_OWNER) | tr A-Z a-z) LOWER_REPOSITORY_OWNER = $(shell echo $(REPOSITORY_OWNER) | tr A-Z a-z)
REGISTRY = "ghcr.io"
TAG = ":main" # Define image to be used in e2e tests. Requires `make` to be available.
E2E_TEST_DOCKER_IMAGE = "$(REGISTRY)/$(LOWER_REPOSITORY_OWNER)/$(DOCKER_E2E_CONTAINER_NAME)$(TAG)" 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 default: help
@ -92,24 +93,27 @@ coverage: deps ## Generate code coverage report
coverhtml: coverage ## Generate HTML coverage report coverhtml: coverage ## Generate HTML coverage report
@go tool cover -html=coverage_cleaned.cov -o coverage_unit.html @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 deploy/dockerfiles: ## Clone Dockerfiles repository
e2e-test-docker-image: deploy/e2e-test-image/Dockerfile @git clone git@github.com:$(REPOSITORY_OWNER)/dockerfiles.git deploy/dockerfiles
@docker build -t $(E2E_TEST_DOCKER_IMAGE) deploy/e2e-test-image
.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 .PHONY: e2e-test
e2e-test: deps ## Run e2e tests 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)" @go test -count=1 ./tests/e2e -v -args -dockerImage="$(E2E_TEST_DOCKER_IMAGE)"
.PHONY: e2e-docker .PHONY: e2e-docker
e2e-docker: docker ## Run e2e tests against the Docker container e2e-docker: docker ## Run e2e tests against the Docker container
docker run --rm -p 127.0.0.1:7200:7200 \ 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 \ -e POSEIDON_SERVER_ADDRESS=0.0.0.0 \
$(DOCKER_OPTS) \ $(DOCKER_OPTS) \
$(DOCKER_TAG) & $(DOCKER_TAG) &
@timeout 30s bash -c "until curl -s -o /dev/null http://127.0.0.1:7200/; do sleep 0.1; done" @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/ # 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/') TRIVY_VERSION = $(shell wget -qO - "https://api.github.com/repos/aquasecurity/trivy/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')

View File

@ -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