Set configuration parameters by variables #32
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: Docker hub auto publish image | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
# Run when file is edited | |
- Dockerfile | |
- start_vsftpd.sh | |
- vsftpd.conf | |
# Run tests for any PRs. | |
pull_request: | |
env: | |
# Image name at docker hub | |
IMAGE_NAME: delfer/alpine-ftp-server | |
jobs: | |
# Run tests. | |
# See also https://docs.docker.com/docker-hub/builds/automated-testing/ | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Run tests | |
run: | | |
if [ -f docker-compose.test.yml ]; then | |
docker-compose --file docker-compose.test.yml build | |
docker-compose --file docker-compose.test.yml run sut | |
else | |
docker build . --file Dockerfile | |
fi | |
push: | |
# Ensure test job passes before pushing image. | |
needs: test | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
# Genrate secret from here https://hub.docker.com/settings/security | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Add Label Schema to Dockerfile | |
run: | | |
# Label Schema based on http://label-schema.org/rc1/ | |
TIME_ISO=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
echo "LABEL org.label-schema.build-date=$TIME_ISO" >> Dockerfile | |
echo "LABEL org.label-schema.name=vsftpd" >> Dockerfile | |
echo "LABEL org.label-schema.url=https://security.appspot.com/vsftpd.html" >> Dockerfile | |
echo "LABEL org.label-schema.vcs-url=https://github.com/delfer/docker-alpine-ftp-server" >> Dockerfile | |
GIT_HASH=$(git rev-parse --short "$GITHUB_SHA") | |
echo "LABEL org.label-schema.vcs-ref=$GIT_HASH" >> Dockerfile | |
echo "LABEL org.label-schema.schema-version=1.0.0-rc.1" >> Dockerfile | |
echo "LABEL org.label-schema.docker.cmd=\"docker run -d -p 21:21 -e USERS=\"username|password\" delfer/alpine-ftp-server\"" >> Dockerfile | |
# Show edited Dockerfile content | |
cat Dockerfile | |
- name: Build and push latest | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 | |
push: true | |
tags: | | |
${{ env.IMAGE_NAME }}:latest |