From 418c8e22f088386a964c86f4a816d95e80edcd01 Mon Sep 17 00:00:00 2001 From: Ilan Zuckerman Date: Mon, 12 Apr 2021 16:15:09 +0300 Subject: [PATCH 1/2] Decoupling the image build process from the flow --- .github/workflows/{main.yml => pr.yml} | 28 ++++++++++++++++-- .github/workflows/publish.yml | 40 ++++++++++++++++++++++++++ Dockerfile | 2 +- docker-compose.yml | 2 +- tests/test_sanity.py | 2 +- version.json | 1 + 6 files changed, 69 insertions(+), 6 deletions(-) rename .github/workflows/{main.yml => pr.yml} (58%) create mode 100644 .github/workflows/publish.yml create mode 100644 version.json diff --git a/.github/workflows/main.yml b/.github/workflows/pr.yml similarity index 58% rename from .github/workflows/main.yml rename to .github/workflows/pr.yml index 27abb75..3d51580 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/pr.yml @@ -1,4 +1,4 @@ -name: CI +name: CI - Build and test on: pull_request: @@ -6,6 +6,9 @@ on: jobs: build: + env: + context: beyond + image_name: beyond runs-on: ubuntu-18.04 steps: - name: Checkout source tree @@ -35,8 +38,27 @@ jobs: tar -xzf geckodriver-v0.26.0-linux64.tar.gz -C geckodriver pip install -r tests/requirements-test.txt - - name: Build the docker-compose stack - run: docker-compose up -d +# - name: Build the docker-compose stack +# run: docker-compose up -d + + - name: Check and verify version.json + id: check_version + run: | + echo -n ::set-output name=IMAGE_TAGS:: + echo $(jq -r '.version' version.json) + + - name: Build Beyond image + uses: docker/build-push-action@v1 + with: + path: . + push: false + repository: ${{ env.image_name }} + tags: ${{ steps.check_version.outputs.IMAGE_TAGS }} + + - name: Run Beyond image + run: | + echo "Running: docker run -d -p 5000:5000 --name ${image_name} ${image_name}:${{ steps.check_version.outputs.IMAGE_TAGS }}" + docker run -d -p 5000:5000 --name ${image_name} ${image_name}:${{ steps.check_version.outputs.IMAGE_TAGS }} - name: Execute tests run: | diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..f055ba3 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,40 @@ +name: CI - Publish to quay.io + +on: + push: + branches: + - master + tags: + - '*' + paths: + - version.json +jobs: + build: + env: + context: beyond + image_name: beyond + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@master + - name: Get image tags + id: image_tags + run: | + echo -n ::set-output name=IMAGE_TAGS:: + VERSION=$(jq -r '.version' version.json) + TAGS=('latest') + if [ "${VERSION}" ] && [ "${VERSION}" != "latest" ]; then + TAGS+=("${VERSION}") + fi + if [[ "${GITHUB_REF}" =~ refs/tags/(.*) ]]; then + TAGS+=("git-${BASH_REMATCH[1]}") + fi + ( IFS=$','; echo "${TAGS[*]}" ) + + - name: Build and publish image to Quay + uses: docker/build-push-action@v1 + with: + registry: quay.io + username: "redhat-beyond+robot" + password: ${{ secrets.REGISTRY_PASSWORD }} + repository: redhat-beyond/beyond + tags: "${{ steps.image_tags.outputs.IMAGE_TAGS }}" diff --git a/Dockerfile b/Dockerfile index 0875a50..e6c5326 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,4 +12,4 @@ COPY . . RUN pip3 install -r requirements.txt EXPOSE 5000 -ENTRYPOINT python3 app.py runserver > web-application.log +ENTRYPOINT python3 app.py runserver > web-application.log \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index daadd5b..beb7ccc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.9' services: beyond: - build: . + image: quay.io/redhat-beyond/beyond container_name: beyond ports: - "5000:5000" diff --git a/tests/test_sanity.py b/tests/test_sanity.py index 2cb22a1..6b74daf 100644 --- a/tests/test_sanity.py +++ b/tests/test_sanity.py @@ -2,7 +2,7 @@ import requests from pystemd.systemd1 import Unit -CONTAINER_NAMES = ['beyond', 'postgres'] +CONTAINER_NAMES = ['beyond'] def test_webserver_response_code(): diff --git a/version.json b/version.json new file mode 100644 index 0000000..1f1324b --- /dev/null +++ b/version.json @@ -0,0 +1 @@ +{"version":"v1.0.0"} \ No newline at end of file From 6d6638308f3b4544bfcfe4bb80b09aa30877fd6a Mon Sep 17 00:00:00 2001 From: Ilan Zuckerman Date: Wed, 28 Apr 2021 16:23:22 +0300 Subject: [PATCH 2/2] test --- .github/workflows/pr.yml | 4 ++-- .github/workflows/publish.yml | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 3d51580..28cb6b2 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -2,12 +2,12 @@ name: CI - Build and test on: pull_request: - branches: [ master ] + branches: + - master jobs: build: env: - context: beyond image_name: beyond runs-on: ubuntu-18.04 steps: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f055ba3..c98dfbe 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,12 +6,15 @@ on: - master tags: - '*' + # The path to monitor for changes. Can be a single file or a wildcard paths: - version.json jobs: build: env: - context: beyond + registry: quay.io + reistry_username: redhat-beyond+robot + registry_repository: redhat-beyond image_name: beyond runs-on: ubuntu-18.04 steps: @@ -33,8 +36,8 @@ jobs: - name: Build and publish image to Quay uses: docker/build-push-action@v1 with: - registry: quay.io - username: "redhat-beyond+robot" + registry: ${{ env.registry }} + username: ${{ env.registry_username }} password: ${{ secrets.REGISTRY_PASSWORD }} - repository: redhat-beyond/beyond + repository: ${{ env.registry_repository }}/${{ env.image_name }} tags: "${{ steps.image_tags.outputs.IMAGE_TAGS }}"