DockerHub Publish #85
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: DockerHub Publish | |
on: | |
push: | |
branches: [ master, most_recent_tag ] | |
workflow_dispatch: # manual trigger (through website or api) | |
env: | |
IMAGE_NAME: rinocommunity/monero | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Get latest Monero tag | |
run: | | |
echo "BUILD_BRANCH=$(curl -s https://api.github.com/repos/monero-project/monero/tags | grep -i name | awk 'NR==1{print $2}' | tr -d "\",")" >> $GITHUB_ENV | |
if: github.ref == 'refs/heads/most_recent_tag' | |
- name: Set source branch when using Monero tag | |
run: | | |
echo "CLONE_BRANCH=${{ env.BUILD_BRANCH }}" >> $GITHUB_ENV | |
if: github.ref == 'refs/heads/most_recent_tag' | |
- name: Get latest Monero master commit hash | |
run: | | |
echo "BUILD_BRANCH=$(curl -s https://api.github.com/repos/monero-project/monero/branches/master | grep -i sha | awk 'NR==1{print $2}' | tr -d "\",")" >> $GITHUB_ENV | |
if: github.ref == 'refs/heads/master' | |
- name: Set source branch when using master branch | |
run: | | |
echo "CLONE_BRANCH=master" >> $GITHUB_ENV | |
if: github.ref == 'refs/heads/master' | |
- name: Log into Dockerhub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USER }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Pull "dependencies1" if it exists | |
run: docker pull $IMAGE_NAME:dependencies1 || true | |
- name: Build updated "dependencies1" if necessary | |
run: docker build --pull | |
--target dependencies1 | |
--cache-from $IMAGE_NAME:dependencies1 | |
-f ./Dockerfile | |
-t $IMAGE_NAME:dependencies1 . | |
- name: Push "dependencies1" | |
run: docker push $IMAGE_NAME:dependencies1 | |
- name: Pull "dependencies2" if it exists | |
run: docker pull $IMAGE_NAME:dependencies2 || true | |
- name: Build updated "dependencies2" if necessary | |
run: docker build --pull | |
--target dependencies2 | |
--cache-from $IMAGE_NAME:dependencies1 | |
--cache-from $IMAGE_NAME:dependencies2 | |
-f ./Dockerfile | |
-t $IMAGE_NAME:dependencies2 . | |
- name: Push "dependencies2" | |
run: docker push $IMAGE_NAME:dependencies2 | |
- name: Pull "dependencies3" if it exists | |
run: docker pull $IMAGE_NAME:dependencies3 || true | |
- name: Build updated "dependencies3" if necessaru | |
run: docker build --pull | |
--target dependencies3 | |
--cache-from $IMAGE_NAME:dependencies1 | |
--cache-from $IMAGE_NAME:dependencies2 | |
--cache-from $IMAGE_NAME:dependencies3 | |
-f ./Dockerfile | |
-t $IMAGE_NAME:dependencies3 . | |
- name: Push "dependencies3" | |
run: docker push $IMAGE_NAME:dependencies3 | |
- name: Pull "builder" if it exists | |
run: docker pull $IMAGE_NAME:builder || true | |
- name: Build updated "builder" if necessary | |
run: docker build --pull | |
--target builder | |
--cache-from $IMAGE_NAME:dependencies1 | |
--cache-from $IMAGE_NAME:dependencies2 | |
--cache-from $IMAGE_NAME:dependencies3 | |
--cache-from $IMAGE_NAME:builder | |
--build-arg BRANCH=${{ env.CLONE_BRANCH }} | |
--build-arg BUILD_BRANCH=${{ env.BUILD_BRANCH }} | |
-f ./Dockerfile | |
-t $IMAGE_NAME:builder . | |
- name: Push "builder" | |
run: docker push $IMAGE_NAME:builder | |
- name: Pull final image if it exists | |
run: docker pull $IMAGE_NAME || true | |
- name: Build updated final image if necessary | |
run: docker build --pull | |
--cache-from $IMAGE_NAME:dependencies1 | |
--cache-from $IMAGE_NAME:dependencies2 | |
--cache-from $IMAGE_NAME:dependencies3 | |
--cache-from $IMAGE_NAME:builder | |
--cache-from $IMAGE_NAME | |
--build-arg BRANCH=${{ env.CLONE_BRANCH }} | |
--build-arg BUILD_BRANCH=${{ env.BUILD_BRANCH }} | |
-f ./Dockerfile | |
-t $IMAGE_NAME . | |
- name: Tag the image with its Monero tag and/or master branch commit hash | |
run: docker tag $IMAGE_NAME $IMAGE_NAME:${{ env.BUILD_BRANCH }} | |
- name: Push the image tagged with its Monero tag and/or master branch commit hash | |
run: docker push $IMAGE_NAME:${{ env.BUILD_BRANCH }} | |
- name: Tag the image with the most_recent_tag | |
run: docker tag $IMAGE_NAME $IMAGE_NAME:most_recent_tag | |
if: github.ref == 'refs/heads/most_recent_tag' | |
- name: Push the image tagged with the most recent monero project repo tag | |
run: docker push $IMAGE_NAME:most_recent_tag | |
if: github.ref == 'refs/heads/most_recent_tag' | |
- name: Push the latest image made from the most recent master commit | |
run: docker push $IMAGE_NAME:latest | |
if: github.ref == 'refs/heads/master' | |