Merge pull request #145 from OCA-UFCG/cicd_aws #29
Workflow file for this run
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: | |
tags: ["*"] | |
jobs: | |
primary-build: | |
runs-on: primary-self-hosted-runner | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Update docker metadata with the tag | |
uses: docker/metadata-action@v4 | |
id: meta | |
with: | |
images: ${{ vars.DOCKER_IMAGE_PROD }} | |
- 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: ${{ secrets.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_PROD }}:latest | |
${{ steps.meta.outputs.tags }} | |
build-args: | | |
NEXT_PUBLIC_HOST_URL=${{ vars.NEXT_PUBLIC_HOST_URL }} | |
NEXT_PUBLIC_GEE_PRIVATE_KEY=${{ secrets.NEXT_PUBLIC_GEE_PRIVATE_KEY }} | |
NEXT_PUBLIC_GA_ID=${{ secrets.NEXT_PUBLIC_GA_ID }} | |
NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN=${{ secrets.NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN }} | |
NEXT_PUBLIC_CONTENTFUL_SPACE=${{ secrets.NEXT_PUBLIC_CONTENTFUL_SPACE }} | |
NEXT_PUBLIC_MAIL_APP_TO=${{ vars.NEXT_PUBLIC_MAIL_APP_TO }} | |
NEXT_PUBLIC_MAIL_APP_CC=${{ vars.NEXT_PUBLIC_MAIL_APP_CC }} | |
NEXT_PUBLIC_MAIL_APP_USER=${{ vars.NEXT_PUBLIC_MAIL_APP_USER }} | |
NEXT_PUBLIC_MAIL_APP_PASS=${{ secrets.NEXT_PUBLIC_MAIL_APP_PASS }} | |
- name: Pull the latest image | |
run: sudo docker pull ${{ vars.DOCKER_IMAGE_PROD }}:latest | |
- name: Stop existing container | |
run: sudo docker rm -f ${{ vars.CONTAINER_NAME_PROD }} || true | |
- name: Run new container | |
run: sudo docker run --restart unless-stopped --name ${{ vars.CONTAINER_NAME_PROD }} -p ${{ vars.HOST_PORT_PROD }}:${{ vars.CONTAINER_PORT }} -d ${{ vars.DOCKER_IMAGE_PROD }}:latest | |
- name: Connect to oca-network | |
run: docker network connect oca-network oca-frontend-app | |
- name: Prune unused Docker images | |
run: sudo docker system prune -f | |
secondary-build: | |
runs-on: secondary-self-hosted-runner | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Update docker metadata with the tag | |
uses: docker/metadata-action@v4 | |
id: meta | |
with: | |
images: ${{ vars.DOCKER_IMAGE_PROD }} | |
- 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: ${{ secrets.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_PROD }}:latest | |
${{ steps.meta.outputs.tags }} | |
build-args: | | |
NEXT_PUBLIC_HOST_URL=${{ vars.NEXT_PUBLIC_HOST_URL }} | |
NEXT_PUBLIC_GEE_PRIVATE_KEY=${{ secrets.NEXT_PUBLIC_GEE_PRIVATE_KEY }} | |
NEXT_PUBLIC_GA_ID=${{ secrets.NEXT_PUBLIC_GA_ID }} | |
NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN=${{ secrets.NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN }} | |
NEXT_PUBLIC_CONTENTFUL_SPACE=${{ secrets.NEXT_PUBLIC_CONTENTFUL_SPACE }} | |
NEXT_PUBLIC_MAIL_APP_TO=${{ vars.NEXT_PUBLIC_MAIL_APP_TO }} | |
NEXT_PUBLIC_MAIL_APP_CC=${{ vars.NEXT_PUBLIC_MAIL_APP_CC }} | |
NEXT_PUBLIC_MAIL_APP_USER=${{ vars.NEXT_PUBLIC_MAIL_APP_USER }} | |
NEXT_PUBLIC_MAIL_APP_PASS=${{ secrets.NEXT_PUBLIC_MAIL_APP_PASS }} | |
- name: Pull the latest image | |
run: sudo docker pull ${{ vars.DOCKER_IMAGE_PROD }}:latest | |
- name: Stop existing container | |
run: sudo docker rm -f ${{ vars.CONTAINER_NAME_PROD }} || true | |
- name: Run new container | |
run: sudo docker run --restart unless-stopped --name ${{ vars.CONTAINER_NAME_PROD }} -p ${{ vars.HOST_PORT_PROD }}:${{ vars.CONTAINER_PORT }} -d ${{ vars.DOCKER_IMAGE_PROD }}:latest | |
- name: Connect to oca network | |
run: docker network connect oca-network oca-frontend-app | |
- name: Prune unused Docker images | |
run: sudo docker system prune -f |