Merge pull request #53 from OCA-UFCG/feat/cms #39
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: CI/CD OCA | |
on: | |
push: | |
branches: ["main"] | |
jobs: | |
build: | |
runs-on: oca-self-hosted-runner | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Stop existing container | |
run: sudo docker rm -f ${{ vars.CONTAINER_NAME_BETA }} || true | |
- name: Remove the old image | |
run: sudo docker rmi ${{ vars.DOCKER_IMAGE_BETA }}:latest || true | |
- name: Update docker metadata with the tag | |
uses: docker/metadata-action@v4 | |
id: meta | |
with: | |
images: ${{ vars.DOCKER_IMAGE_BETA }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ vars.DOCKER_USERNAME }} | |
password: ${{ vars.DOCKER_PASSWORD }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
file: Dockerfile.production | |
labels: ${{ steps.meta.outputs.labels }} | |
tags: | | |
${{ vars.DOCKER_IMAGE_BETA }}:latest | |
${{ steps.meta.outputs.tags }} | |
build-args: | | |
NEXT_PUBLIC_HOST_URL=${{ vars.NEXT_PUBLIC_HOST_URL_BETA }} | |
NEXT_PUBLIC_GEE_PRIVATE_KEY=${{ secrets.NEXT_PUBLIC_GEE_PRIVATE_KEY }} | |
NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN=${{ secrets.NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN }} | |
NEXT_PUBLIC_CONTENTFUL_SPACE=${{ secrets.NEXT_PUBLIC_CONTENTFUL_SPACE }} | |
- name: Run new container | |
run: sudo docker run --name ${{ vars.CONTAINER_NAME_BETA }} -p ${{ vars.HOST_PORT_BETA }}:${{ vars.CONTAINER_PORT }} -d ${{ vars.DOCKER_IMAGE_BETA }}:latest | |
- name: Prune unused Docker images | |
run: sudo docker system prune -f |