From 7a11a7b7920f8f67b3cca9df235a6e9708c4276a Mon Sep 17 00:00:00 2001 From: Mohammad Ahtasham ul Hassan Date: Mon, 12 Dec 2022 17:19:55 +0500 Subject: [PATCH] build: add publish workflow --- .github/workflows/docker-publish.yml | 50 ++++++++++++++++++++++------ Makefile | 16 --------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 7938a27cd40..37bcde3fa61 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,23 +1,51 @@ -name: Push Docker Images +name: Build and Push Docker Images on: push: branches: - master - + tags: + - open-release/* jobs: - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ push: runs-on: ubuntu-latest - if: github.event_name == 'push' steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v2 + + # Use the release name as the image tag if we're building an open release tag. + # Examples: if we're building 'open-release/maple.1', tag the image as 'maple.1'. + # Otherwise, we must be building from a push to master, so use 'latest'. + - name: Get tag name + id: get-tag-name + uses: actions/github-script@v5 + with: + script: | + const releasePrefix = 'refs/tags/open-release/'; + const tagName = context.ref.split(releasePrefix)[1] || 'latest'; + console.log('Will use tag: ' + tagName); + return tagName; + result-encoding: string + + - name: Build and push Dev Docker image + uses: docker/build-push-action@v1 + with: + push: true + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + target: dev + repository: edxops/discovery-dev + tags: ${{ steps.get-tag-name.outputs.result }},${{ github.sha }} - - name: Build and Push docker image - env: - DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - run : make docker_push + # The current priority is to get the devstack off of Ansible based Images. Once that is done, we can come back to this part to get + # suitable images for smaller prod environments. + # - name: Build and push prod Docker image + # uses: docker/build-push-action@v1 + # with: + # push: true + # username: ${{ secrets.DOCKERHUB_USERNAME }} + # password: ${{ secrets.DOCKERHUB_PASSWORD }} + # target: prod + # repository: edxops/discovery-prod + # tags: ${{ steps.get-tag-name.outputs.result }},${{ github.sha }} \ No newline at end of file diff --git a/Makefile b/Makefile index 968c1a02482..836e54cd73c 100644 --- a/Makefile +++ b/Makefile @@ -134,22 +134,6 @@ docs: check_keywords: ## Scan the Django models in all installed apps in this project for restricted field names python manage.py check_reserved_keywords --override_file db_keyword_overrides.yml -docker_build: - docker build . -f Dockerfile --target app -t openedx/discovery - docker build . -f Dockerfile --target newrelic -t openedx/discovery:latest-newrelic - -docker_tag: docker_build - docker tag openedx/discovery openedx/discovery:${GITHUB_SHA} - docker tag openedx/discovery:latest-newrelic openedx/discovery:${GITHUB_SHA}-newrelic - -docker_auth: - echo "$$DOCKERHUB_PASSWORD" | docker login -u "$$DOCKERHUB_USERNAME" --password-stdin - -docker_push: docker_tag docker_auth ## push to docker hub - docker push 'openedx/discovery:latest' - docker push "openedx/discovery:${GITHUB_SHA}" - docker push 'openedx/discovery:latest-newrelic' - docker push "openedx/discovery:${GITHUB_SHA}-newrelic" install_transifex_client: ## Install the Transifex client curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash