Skip to content

Commit

Permalink
improve Docker workflows (allenai#4210)
Browse files Browse the repository at this point in the history
* improve Docker workflows

* clean up
  • Loading branch information
epwalsh authored May 8, 2020
1 parent b916720 commit edf91ac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set Docker label
- name: Set Docker tag
run: |
if [[ $GITHUB_EVENT_NAME == 'release' ]]; then
echo "::set-env name=DOCKER_LABEL::${GITHUB_REF#refs/tags/}";
echo "::set-env name=DOCKER_TAG::${GITHUB_REF#refs/tags/}";
else
echo "::set-env name=DOCKER_LABEL::$GITHUB_SHA";
echo "::set-env name=DOCKER_TAG::$GITHUB_SHA";
fi
- name: Build test image
run: |
make docker-test-image DOCKER_LABEL="$DOCKER_LABEL"
make docker-test-image
- name: Run GPU tests
run: |
make docker-test-run DOCKER_LABEL="$DOCKER_LABEL" ARGS='gpu-test'
make docker-test-run ARGS='gpu-test'
check_core:
name: Check Core
Expand Down Expand Up @@ -259,6 +259,14 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set Docker image name
run: |
if [[ $GITHUB_EVENT_NAME == 'release' ]]; then
echo "::set-env name=DOCKER_IMAGE_NAME::allennlp/allennlp:${GITHUB_REF#refs/tags/}";
else
echo "::set-env name=DOCKER_IMAGE_NAME::allennlp/commit:$GITHUB_SHA";
fi
- name: Download core package
uses: actions/download-artifact@v1
with:
Expand All @@ -278,27 +286,19 @@ jobs:
if: github.repository == 'allenai/allennlp' && github.event_name == 'push'
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
# Tag with current commit and 'latest'.
docker tag allennlp/allennlp:latest allennlp/commit:$GITHUB_SHA
docker tag allennlp/allennlp:latest allennlp/commit:latest
# Push both tags.
docker push allennlp/commit:$GITHUB_SHA
docker push allennlp/commit:latest
docker push $DOCKER_IMAGE_NAME
- name: Upload release image
# Only run this for releases on the main repo, not forks.
if: github.repository == 'allenai/allennlp' && github.event_name == 'release'
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
TAG=${GITHUB_REF#refs/tags/};
# Tag with release version.
docker tag allennlp/allennlp:latest allennlp/allennlp:$TAG
# Tag with latest.
docker tag $DOCKER_IMAGE_NAME allennlp/allennlp:latest
# Push both tags.
docker push allennlp/allennlp:$TAG
docker push $DOCKER_IMAGE_NAME
docker push allennlp/allennlp:latest
# Builds the API documentation and pushes it to the appropriate folder in the
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set Docker tag
run: |
echo "::set-env name=DOCKER_TAG::$GITHUB_SHA";
- name: Build test image
run: |
make docker-test-image DOCKER_LABEL="$GITHUB_SHA"
make docker-test-image
- name: Run GPU tests
run: |
make docker-test-run DOCKER_LABEL="$GITHUB_SHA" ARGS='gpu-test'
make docker-test-run ARGS='gpu-test'
check_core:
name: Check Core
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ MD_DOCS_CONF_SRC = mkdocs-skeleton.yml
MD_DOCS_TGT = site/
MD_DOCS_EXTRAS = $(addprefix $(MD_DOCS_ROOT),README.md LICENSE.md ROADMAP.md CONTRIBUTING.md)

DOCKER_LABEL = latest
DOCKER_TAG = allennlp/allennlp:$(DOCKER_LABEL)
DOCKER_TEST_TAG = allennlp/test:$(DOCKER_LABEL)
DOCKER_RUN_CMD = docker run --rm -v $$HOME/.allennlp:/root/.allennlp
DOCKER_TAG = latest
DOCKER_IMAGE_NAME = allennlp/allennlp:$(DOCKER_TAG)
DOCKER_TEST_IMAGE_NAME = allennlp/test:$(DOCKER_TAG)
DOCKER_RUN_CMD = docker run --rm -v $$HOME/.allennlp:/root/.allennlp

ifeq ($(shell uname),Darwin)
ifeq ($(shell which gsed),)
Expand Down Expand Up @@ -134,16 +134,16 @@ docker-image :
docker build \
--pull \
-f Dockerfile \
-t $(DOCKER_TAG) .
-t $(DOCKER_IMAGE_NAME) .

.PHONY : docker-run
docker-run :
$(DOCKER_RUN_CMD) $(DOCKER_TAG) $(ARGS)
$(DOCKER_RUN_CMD) $(DOCKER_IMAGE_NAME) $(ARGS)

.PHONY : docker-test-image
docker-test-image :
docker build --pull -f Dockerfile.test -t $(DOCKER_TEST_TAG) .
docker build --pull -f Dockerfile.test -t $(DOCKER_TEST_IMAGE_NAME) .

.PHONY : docker-test-run
docker-test-run :
$(DOCKER_RUN_CMD) --gpus 2 $(DOCKER_TEST_TAG) $(ARGS)
$(DOCKER_RUN_CMD) --gpus 2 $(DOCKER_TEST_IMAGE_NAME) $(ARGS)

0 comments on commit edf91ac

Please sign in to comment.