2021-02-25 16:36:10 +00:00
|
|
|
# Template docker-push
|
|
|
|
|
|
|
|
# This template allows you to build and push your docker image to a Docker Hub account.
|
|
|
|
# The workflow allows running tests, code linting and security scans on feature branches (as well as master).
|
|
|
|
# The docker image will be validated and pushed to the docker registry after the code is merged to master.
|
|
|
|
|
|
|
|
# Prerequisites: $DOCKERHUB_USERNAME, $DOCKERHUB_PASSWORD setup as deployment variables
|
|
|
|
|
|
|
|
image: atlassian/default-image:2
|
|
|
|
|
|
|
|
pipelines:
|
|
|
|
default:
|
|
|
|
- parallel:
|
|
|
|
- step:
|
2021-02-25 17:20:47 +00:00
|
|
|
name: Parallel Build and Test
|
2021-02-25 16:36:10 +00:00
|
|
|
script:
|
|
|
|
- IMAGE_NAME=$BITBUCKET_REPO_SLUG
|
2021-02-25 17:02:21 +00:00
|
|
|
- docker build . --file Dockerfile --tag ${DOCKERHUB_NAMESPACE}/${IMAGE_NAME}
|
2021-02-25 16:36:10 +00:00
|
|
|
services:
|
|
|
|
- docker
|
|
|
|
caches:
|
|
|
|
- docker
|
|
|
|
- step:
|
|
|
|
name: Lint the Dockerfile
|
|
|
|
image: hadolint/hadolint:latest-debian
|
|
|
|
script:
|
|
|
|
- hadolint Dockerfile
|
|
|
|
branches:
|
|
|
|
master:
|
|
|
|
- step:
|
2021-02-25 17:20:47 +00:00
|
|
|
name: Master Build and Test
|
2021-02-25 16:36:10 +00:00
|
|
|
script:
|
|
|
|
- IMAGE_NAME=$BITBUCKET_REPO_SLUG
|
2021-02-25 17:02:21 +00:00
|
|
|
- docker build . --file Dockerfile --tag ${DOCKERHUB_NAMESPACE}/${IMAGE_NAME}
|
2021-02-25 16:36:10 +00:00
|
|
|
- docker save ${IMAGE_NAME} --output "${IMAGE_NAME}.tar"
|
|
|
|
services:
|
|
|
|
- docker
|
|
|
|
caches:
|
|
|
|
- docker
|
|
|
|
artifacts:
|
|
|
|
- "*.tar"
|
|
|
|
- step:
|
|
|
|
name: Deploy to Production
|
|
|
|
deployment: Production
|
|
|
|
script:
|
|
|
|
- echo ${DOCKERHUB_PASSWORD} | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
|
|
|
|
- IMAGE_NAME=$BITBUCKET_REPO_SLUG
|
2021-02-25 17:20:47 +00:00
|
|
|
- NAMESPACE=$DOCKERHUB_NAMESPACE
|
|
|
|
- docker push ${NAMESPACE}/${IMAGE_NAME}:latest
|
2021-02-25 16:36:10 +00:00
|
|
|
services:
|
|
|
|
- docker
|