Update Dockerfile #105
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: Deploy | |
on: | |
push: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
name: Build | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
with: | |
install: true | |
- name: Build | |
run: | | |
docker build \ | |
--tag ci:${{ github.run_number }} \ | |
--progress plain \ | |
--file ./Dockerfile \ | |
--load \ | |
. | |
- name: Save tarball | |
run: | | |
docker save --output output.tar ci:${{ github.run_number }} | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: ci-${{ github.run_number }}.tar | |
path: output.tar | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [build] | |
name: Deploy | |
strategy: | |
matrix: | |
registry: | |
- { | |
url: "https://index.docker.io/v1/", | |
username: dockerID, | |
password: dockerPassword, | |
repo: yaoa/cloud-media-scripts | |
} | |
- { | |
url: ghcr.io/alexyao2015, | |
username: CR_USER, | |
password: CR_PAT, | |
repo: ghcr.io/alexyao2015/cloud-media-scripts/core | |
} | |
steps: | |
- name: Download container artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: ci-${{ github.run_number }}.tar | |
- name: Set Docker Repository & Load Image | |
run: | | |
docker load --input output.tar | |
export DOCKER_REPO=${{ matrix.registry.repo }} | |
export DOCKER_IMAGE_NAME=ci:${{ github.run_number }} | |
echo "DOCKER_REPO=${DOCKER_REPO}" >> $GITHUB_ENV | |
echo "DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME}" >> $GITHUB_ENV | |
echo Repository set as: ${DOCKER_REPO} | |
echo Image set as: ${DOCKER_IMAGE_NAME} | |
- name: Login | |
run: | | |
docker login ${{ matrix.registry.url }} -u ${{ secrets[matrix.registry.username] }} -p ${{ secrets[matrix.registry.password] }} | |
- name: Deploy Commit ID | |
if: ${{ github.head_ref == '' && github.sha != '' }} | |
run: | | |
docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REPO}:$GITHUB_SHA | |
docker push ${DOCKER_REPO}:$GITHUB_SHA | |
- name: Deploy Run Number | |
if: ${{ github.head_ref == '' && github.sha != '' }} | |
run: | | |
docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REPO}:$GITHUB_RUN_NUMBER | |
docker push ${DOCKER_REPO}:$GITHUB_RUN_NUMBER | |
- name: Deploy Latest | |
if: ${{ github.head_ref == '' && github.ref == 'refs/heads/master' }} | |
run: | | |
docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REPO}:latest | |
docker push ${DOCKER_REPO}:latest | |
- name: Deploy Develop | |
if: ${{ github.head_ref == '' && startsWith(github.ref, 'refs/heads/dev') }} | |
run: | | |
docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REPO}:latest-develop | |
docker push ${DOCKER_REPO}:latest-develop | |
- name: Deploy Branch | |
if: ${{ github.head_ref == '' && startsWith(github.ref, 'refs/heads/') }} | |
run: | | |
docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REPO}:${GITHUB_REF##*/} | |
docker push ${DOCKER_REPO}:${GITHUB_REF##*/} | |
- name: Deploy Tag | |
if: ${{ github.head_ref == '' && startsWith(github.ref, 'refs/tags/') }} | |
run: | | |
docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REPO}:${GITHUB_REF##*/} | |
docker push ${DOCKER_REPO}:${GITHUB_REF##*/} |