2.10.0 #507
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 Image CI | |
on: | |
workflow_dispatch: | |
push: | |
paths-ignore: | |
- 'docs/**' | |
branches: | |
- '**' | |
tags: | |
- v* | |
env: | |
DOCKER_BUILDKIT: 1 | |
concurrency: | |
group: ${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
image: "agencebio/cartobio-api:${{ steps.publish.outputs.tag }}" | |
version: ${{ steps.version.outputs.name }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: docker/setup-buildx-action@v2 | |
- run: docker build -t agencebio/cartobio-api . | |
- name: Test the Docker image | |
run: docker run -e NOTIFICATIONS_AB_CARTOBIO_USER -e NOTIFICATIONS_AB_CARTOBIO_PASSWORD -e NOTIFICATIONS_AB_SSO_CLIENT_ID -e NOTIFICATIONS_AB_SSO_CLIENT_SECRET -e NOTIFICATIONS_AB_ENDPOINT -e CARTOBIO_JWT_SECRET -e CI agencebio/cartobio-api npm test | |
env: | |
CI: true | |
NOTIFICATIONS_AB_ENDPOINT: https://preprod-notifications.agencebio.org:444 | |
CARTOBIO_JWT_SECRET: "${{ secrets.CARTOBIO_JWT_SECRET }}" | |
NOTIFICATIONS_AB_SSO_CLIENT_ID: "test" | |
NOTIFICATIONS_AB_SSO_CLIENT_SECRET: "test" | |
NOTIFICATIONS_AB_CARTOBIO_USER: "test" | |
NOTIFICATIONS_AB_CARTOBIO_PASSWORD: "test" | |
- name: Login to Docker Hub | |
run: echo "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin | |
- name: Assign Docker ref | |
id: publish | |
run: | | |
if [[ $GITHUB_REF == 'refs/heads/main' ]]; then | |
echo "tag=latest" >> $GITHUB_OUTPUT | |
else | |
echo "tag=${GITHUB_REF_NAME#v*}" >> $GITHUB_OUTPUT | |
fi | |
- name: Publish to Docker Hub | |
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }} | |
run: | | |
docker tag agencebio/cartobio-api agencebio/cartobio-api:${{ steps.publish.outputs.tag }} | |
docker push agencebio/cartobio-api:${{ steps.publish.outputs.tag }} | |
- name: Get package.json version | |
id: version | |
run: echo name=$(node -p "require('./package.json').version") >> $GITHUB_OUTPUT | |
deploy-staging: | |
needs: [build] | |
if: github.ref == 'refs/heads/main' | |
environment: staging | |
runs-on: ubuntu-latest | |
steps: | |
- uses: garygrossgarten/[email protected] | |
with: | |
host: ${{ secrets.AGENCEBIO_SSH_HOST }} | |
username: ${{ secrets.AGENCEBIO_SSH_USERNAME }} | |
privateKey: ${{ secrets.AGENCEBIO_SSH_PRIVATE_KEY }} | |
command: | | |
docker pull ${{ needs.build.outputs.image }} \ | |
&& docker stop cartobio-api-staging \ | |
&& docker container rm cartobio-api-staging \ | |
&& docker run -d --restart unless-stopped \ | |
-p 127.0.0.1:7500:8000 \ | |
--env-file=.env.cartobio-api-staging \ | |
--env SENTRY_RELEASE=${{ needs.build.outputs.version }}-dev-${{ github.sha }} \ | |
--name cartobio-api-staging \ | |
${{ needs.build.outputs.image }} | |
deploy-production: | |
needs: [build] | |
if: startsWith(github.ref, 'refs/tags/') | |
environment: production | |
runs-on: ubuntu-latest | |
steps: | |
- uses: garygrossgarten/[email protected] | |
with: | |
host: ${{ secrets.AGENCEBIO_SSH_HOST }} | |
username: ${{ secrets.AGENCEBIO_SSH_USERNAME }} | |
privateKey: ${{ secrets.AGENCEBIO_SSH_PRIVATE_KEY }} | |
command: | | |
docker pull ${{ needs.build.outputs.image }} \ | |
&& docker stop cartobio-api-production \ | |
&& docker container rm cartobio-api-production \ | |
&& docker run -d --restart unless-stopped \ | |
-p 127.0.0.1:8000:8000 \ | |
--env-file=.env.cartobio-api-production \ | |
--name cartobio-api-production \ | |
${{ needs.build.outputs.image }} |